Ejemplo n.º 1
0
void ConvType::write_cpp_decl( StreamSepMaker<Stream> &on ) {
    on << "struct " << cpp_name() << " : public Model {";
    on.nsp += 4;

    // constructors
    on << cpp_name() << "( char  *__ptr, Model *__par, char __bof ) : __ptr( __ptr ), __par( __par ), __bof( __bof ) {";
    on << "}";

    // attributes
    for( const ConvType::Attribute &attr : attributes ) {
        if ( ConvType *t = attr.type ) {
            on << t->cpp_name() << " " << attr.name << "() {";
            on << "    return "<< t->cpp_name() << "( __ptr, __par, __bof );";
            on << "}";
        }
    }

    // size and alig
    Past s = base_size, a = base_alig, p = new Ast_Symbol( "__ptr" ), b = new Ast_Symbol( "__bof" );

    on << "int __size() const {";
    on << "    return " << s << ";";
    on << "}";
    on << "int __alig() const {";
    on << "    return " << a << ";";
    on << "}";

    on << "char  *__ptr;";
    on << "Model *__par;";
    on << "char   __bof;";

    on.nsp -= 4;
    on << "};";
}
Ejemplo n.º 2
0
void inl_gen::generate(const mfast::aggregate_view_info& info)
{
  std::string ns_prefix;
  std::string my_name = cpp_name(info.name_);

  if (this->cpp_ns_ != info.instruction_->cpp_ns())
  {
    ns_prefix = info.instruction_->cpp_ns();
    ns_prefix += "::";
  }

  out_ << "inline " << my_name << "::"<< my_name << "(const " << ns_prefix <<  cpp_name(info.instruction_->name()) << "_cref& ref)\n"
       << "  : ref_(ref)\n"
       << "{\n"
       << "}\n\n"
       << "inline mfast::view_iterator " << my_name << "::begin() const\n"
       << "{\n"
       << "  return mfast::view_iterator(ref_, info_.data_.begin(), info_.max_depth_);\n"
       << "}\n\n"
       << "inline mfast::view_iterator  " << my_name << "::end() const\n"
       << "{\n"
       << "  return mfast::view_iterator(info_.data_.end()-1);\n"
       << "}\n\n"
       << "template <typename FieldAccessor>\n"
       << "inline void  " << my_name << "::accept_accessor(FieldAccessor& accessor) const\n"
       << "{\n"
       << "  BOOST_FOREACH(mfast::field_cref f, *this)\n"
       << "  {\n"
       << "    if (FieldAccessor::visit_absent || f.present())"
       << "      f.accept_accessor(accessor);\n"
       << "  }\n"
       << "}\n";
}
Ejemplo n.º 3
0
	void Oni_Model_attachObjectToBone(Oni_ModelPtr obj, char* name, Oni_ModelPtr obj2){
		Oni::Model* model = (Oni::Model*)(obj);
		Oni::Model* otherModel = (Oni::Model*)(obj2);
		
		std::string cpp_name(name);
		model->attachObjectToBone(cpp_name, otherModel);
	}
Ejemplo n.º 4
0
void cpp_gen::visit(const mfast::group_field_instruction* inst, void*)
{
  std::string name( cpp_name( inst ) );
  std::size_t index = inst->field_index();


  add_to_instruction_list(name);
  prefixes_.push_back(name);

  if (  !contains_only_templateRef(inst) ) {
    subinstructions_list_.resize(subinstructions_list_.size()+1);
    traverse(inst, "");
  }

  std::string subinstruction_arg = get_subinstructions(inst);

  out_ << "const static mfast::group_field_instruction\n"
       << prefix_string() << name << "_instruction(\n"
       << "  "<<  index << ",\n"
       << "  " << get_presence(inst) << ",\n"
       << "  " << inst->id() << ", // id\n"
       << "  \"" << inst->name() << "\", // name\n"
       << "  \"" << inst->ns() << "\", // ns\n"
       << "  \"" << inst->dictionary() << "\", // dictionary\n"
       << subinstruction_arg
       << "  \"" << inst->typeref_name() << "\", // typeRef name \n"
       << "  \"" << inst->typeref_ns() << "\"); // typeRef ns \n\n";


}
Ejemplo n.º 5
0
void inl_gen::traverse(const mfast::group_field_instruction* inst, const char* name_suffix)
{
  std::string saved_mref_scope = mref_scope_.str();
  mref_scope_ << cpp_name(inst) << name_suffix << "_mref::";
  codegen_base::traverse(inst, name_suffix);
  reset_scope(mref_scope_, saved_mref_scope);
}
Ejemplo n.º 6
0
void cpp_gen::visit(const mfast::decimal_field_instruction* inst, void*)
{
  std::string name( cpp_name( inst ) );
  if (inst->mantissa_instruction() ) {
    // it has a separate mantissa instruction
    std::string mantisa_name(name);
    mantisa_name += "_mantissa";
    std::string context = gen_op_context(mantisa_name.c_str(), inst->mantissa_instruction()->op_context());

    out_ << "static mantissa_field_instruction\n"
         << prefix_string() << mantisa_name << "_instruction(\n"
         << "  " << get_operator_name(inst->mantissa_instruction()) << ",\n"
         << "  "<< context << ",  // mantissa opContext\n"
         << "  int_value_storage<int64_t>("
         << get_initial_value<int64_t>(inst->mantissa_instruction()->initial_value(), "LL")
         << "));// mantissa inital value\n\n";
  }

  gen_field(inst, gen_op_context(inst->name(), inst->op_context()), "decimal");

  if ( inst->mantissa_instruction() ) {
    out_ << "  &" << prefix_string() << name << "_mantissa_instruction,\n";
  }

  const mfast::value_storage& init_value = inst->initial_value();

  out_ << "  decimal_value_storage(";
  if (!init_value.is_empty())
    out_ <<  init_value.of_decimal.mantissa_ << "LL, " << static_cast<int> (init_value.of_decimal.exponent_);
  out_ << ")); // initial_value\n\n";

}
Ejemplo n.º 7
0
void cpp_gen::visit(const mfast::sequence_field_instruction* inst, void*)
{
  std::string name( cpp_name( inst ) );
  std::size_t index = inst->field_index();

  add_to_instruction_list(name);
  prefixes_.push_back(name);

  if (inst->length_instruction()) {
    std::string context = gen_op_context(inst->length_instruction()->name(),
                                         inst->length_instruction()->op_context());

    // length
    out_ << "static uint32_field_instruction\n"
         << prefix_string() << name << "_length_instruction(\n"
         << "  0,"
         << "  " << get_operator_name(inst->length_instruction()) << ",\n"
         << "  " << get_presence(inst->length_instruction()) << ",\n"
         << "  " << inst->length_instruction()->id() << ", // id\n"
         << "  \""<< inst->length_instruction()->name() << "\", // name\n"
         << "  \""<< inst->length_instruction()->ns() << "\", // ns\n"
         << "  "<< context << ",  // opContext\n"
         << "  int_value_storage<uint32_t>(";
    if (!inst->length_instruction()->initial_value().is_empty())
      out_ << inst->length_instruction()->initial_value().get<uint32_t>() << "U";
    out_ <<  ")); // initial_value\n\n";
  }


  if ( !contains_only_templateRef(inst) ) {
    subinstructions_list_.resize(subinstructions_list_.size()+1);
    traverse(inst, "_element");
  }

  std::string lengthInstruction;

  if (inst->length_instruction()) {
    std::stringstream strm;
    strm << "&" << prefix_string()  << name <<  "_length_instruction";
    lengthInstruction = strm.str();
  }

  std::string subinstruction_arg = get_subinstructions(inst);

  out_ << "const static mfast::sequence_field_instruction\n"
       << prefix_string() << name << "_instruction(\n"
       << "  "<<  index << ",\n"
       << "  " << get_presence(inst) << ",\n"
       << "  " << inst->id() << ", // id\n"
       << "  \"" << inst->name() << "\", // name\n"
       << "  \"" << inst->ns() << "\", // ns\n"
       << "  \"" << inst->dictionary() << "\", // dictionary\n"
       << subinstruction_arg
       << "  "<< lengthInstruction << ", // length\n"
       << "  \"" << inst->typeref_name() << "\", // typeRef name \n"
       << "  \"" << inst->typeref_ns() << "\"); // typeRef ns \n\n";
}
Ejemplo n.º 8
0
	Oni_Animation_TrackPtr Oni_Animation_getAnimationTrack(Oni_AnimationPtr obj, char* name){
		Oni::Animation* animation = (Oni::Animation*)(obj);
		
		std::string cpp_name(name);
		Oni::AnimationTrack* track = animation->getAnimationTrack(cpp_name);
		
		Oni_Animation_TrackPtr ptr_track = (Oni_Animation_TrackPtr)track;
		
		return ptr_track;
	}
Ejemplo n.º 9
0
	Oni_Animation_BonePtr Oni_Animation_getBone(Oni_AnimationPtr obj, char* name){
		Oni::Animation* animation = (Oni::Animation*)(obj);
		
		std::string cpp_name(name);
		Oni::AnimationBone* bone = animation->getBone(cpp_name);
		
		Oni_Animation_BonePtr ptr_bone = (Oni_Animation_BonePtr)bone;
		
		return ptr_bone;
	}
Ejemplo n.º 10
0
void inl_gen::gen_primitive (const char* cpp_type, const mfast::field_instruction* inst, void* pIndex)
{
  std::string name (cpp_name(inst));
  std::stringstream cref_type_name;
  cref_type_name << "mfast::" << cpp_type << "_cref";
  std::stringstream mref_type_name;
  mref_type_name << "mfast::" << cpp_type << "_mref";

  gen_accessors(inst, name, cref_type_name.str(), mref_type_name.str(), pIndex);
}
Ejemplo n.º 11
0
	void Oni_Light_initialize(Oni_LightPtr obj, Ogre_WindowPtr obj2, char* name, Ogre_NodePtr parent){
		Oni::Light* light = (Oni::Light*)(obj);
		GameApplication* game = (GameApplication*)obj2;
		
		std::string cpp_name(name);
		
		Ogre::Node* parentNode = (Ogre::Node*)(parent);
		
		light->initialize(game->getSceneMgr(), cpp_name, parentNode);
	}
Ejemplo n.º 12
0
	void Oni_Model_initialize(Oni_ModelPtr obj, Ogre_WindowPtr obj2, char* name, char* filename, Ogre_NodePtr parent){
		Oni::Model* model = (Oni::Model*)(obj);
		GameApplication* game = (GameApplication*)obj2;
		
		std::string cpp_name(name);
		std::string cpp_filename(filename);
		
		Ogre::Node* parentNode = (Ogre::Node*)(parent);
		
		model->initialize(game->getSceneMgr(), cpp_name, cpp_filename, parentNode);
	}
Ejemplo n.º 13
0
void cpp_gen::gen_int_vector(const char* cpp_type, const mfast::vector_field_instruction_base* inst)
{
  std::string name( cpp_name( inst ) );
  std::size_t index = inst->field_index();
  // std::string context = gen_op_context(inst->name(), inst->op_context());

  out_ << "const static " << cpp_type << "_field_instruction\n"
       << prefix_string() << name << "_instruction(\n"
       << "  " << index << ",\n"
       << "  " << get_presence(inst) << ",\n"
       << "  " << inst->id() << ", // id\n"
       << "  \""<< inst->name() << "\", // name\n"
       << "  \""<< inst->ns() << "\"); // ns\n";

  add_to_instruction_list(name);
}
Ejemplo n.º 14
0
void cpp_gen::visit(const mfast::template_instruction* inst, void*)
{
  if (inst->subinstructions_count() == 0)
    return;

  std::string name( cpp_name( inst ) );

  prefixes_.push_back(name);

  subinstructions_list_.resize(subinstructions_list_.size()+1);

  out_ << "const " << name << "::instruction_type*\n"
       << name << "::instruction()\n"
       << "{\n";

  traverse(inst);

  output_subinstructions();
  prefixes_.pop_back();

  template_instructions_ << "  " << name << "::instruction(),\n";

  out_ << "  const static " << name << "::instruction_type the_instruction(\n"
       << "    " << inst->id() << ", // id\n"
       << "    \"" << inst->name() << "\", // name\n"
       << "    \""<< inst->ns() << "\", // ns\n"
       << "    \""<< inst->template_ns() << "\", // templateNs\n"
       << "    \""<< inst->dictionary() << "\", // dictionary\n"
       << "    "<< name << "__subinstructions,\n"
       << "    "<< inst->subinstructions_count() << ", // num_fields\n"
       << "    " << inst->has_reset_attribute() << ", // reset\n"
       << "  \"" << inst->typeref_name() << "\", // typeRef name \n"
       << "  \"" << inst->typeref_ns() << "\"); // typeRef ns \n\n"
       << "  return &the_instruction;\n"
       << "}\n\n";
}
Ejemplo n.º 15
0
codet cpp_typecheckt::cpp_constructor(
  const source_locationt &source_location,
  const exprt &object,
  const exprt::operandst &operands)
{
  exprt object_tc=object;

  typecheck_expr(object_tc);

  elaborate_class_template(object_tc.type());

  typet tmp_type(object_tc.type());
  follow_symbol(tmp_type);

  assert(!is_reference(tmp_type));

  if(tmp_type.id()==ID_array)
  {
    // We allow only one operand and it must be tagged with '#array_ini'.
    // Note that the operand is an array that is used for copy-initialization.
    // In the general case, a program is not allow to use this form of
    // construct. This way of initializing an array is used internaly only.
    // The purpose of the tag #arra_ini is to rule out ill-formed
    // programs.

    if(!operands.empty() && !operands.front().get_bool("#array_ini"))
    {
      error().source_location=source_location;
      error() << "bad array initializer" << eom;
      throw 0;
    }

    assert(operands.empty() || operands.size()==1);

    if(operands.empty() && cpp_is_pod(tmp_type))
    {
      codet nil;
      nil.make_nil();
      return nil;
    }

    const exprt &size_expr=
      to_array_type(tmp_type).size();

    if(size_expr.id()=="infinity")
    {
      // don't initialize
      codet nil;
      nil.make_nil();
      return nil;
    }

    exprt tmp_size=size_expr;
    make_constant_index(tmp_size);

    mp_integer s;
    if(to_integer(tmp_size, s))
    {
      error().source_location=source_location;
      error() << "array size `" << to_string(size_expr)
              << "' is not a constant" << eom;
      throw 0;
    }

    /*if(cpp_is_pod(tmp_type))
    {
      code_expressiont new_code;
      exprt op_tc=operands.front();
      typecheck_expr(op_tc);
       // Override constantness
      object_tc.type().set("#constant", false);
      object_tc.set("#lvalue", true);
      side_effect_exprt assign("assign");
      assign.add_source_location()=source_location;
      assign.copy_to_operands(object_tc, op_tc);
      typecheck_side_effect_assignment(assign);
      new_code.expression()=assign;
      return new_code;
    }
    else*/
    {
      codet new_code(ID_block);

      // for each element of the array, call the default constructor
      for(mp_integer i=0; i < s; ++i)
      {
        exprt::operandst tmp_operands;

        exprt constant=from_integer(i, index_type());
        constant.add_source_location()=source_location;

        exprt index(ID_index);
        index.copy_to_operands(object);
        index.copy_to_operands(constant);
        index.add_source_location()=source_location;

        if(!operands.empty())
        {
          exprt operand(ID_index);
          operand.copy_to_operands(operands.front());
          operand.copy_to_operands(constant);
          operand.add_source_location()=source_location;
          tmp_operands.push_back(operand);
        }

        exprt i_code =
          cpp_constructor(source_location, index, tmp_operands);

        if(i_code.is_nil())
        {
          new_code.is_nil();
          break;
        }

        new_code.move_to_operands(i_code);
      }
      return new_code;
    }
  }
  else if(cpp_is_pod(tmp_type))
  {
    code_expressiont new_code;
    exprt::operandst operands_tc=operands;

    for(exprt::operandst::iterator
      it=operands_tc.begin();
      it!=operands_tc.end();
      it++)
    {
      typecheck_expr(*it);
      add_implicit_dereference(*it);
    }

    if(operands_tc.empty())
    {
      // a POD is NOT initialized
      new_code.make_nil();
    }
    else if(operands_tc.size()==1)
    {
      // Override constantness
      object_tc.type().set(ID_C_constant, false);
      object_tc.set(ID_C_lvalue, true);
      side_effect_exprt assign(ID_assign);
      assign.add_source_location()=source_location;
      assign.copy_to_operands(object_tc, operands_tc.front());
      typecheck_side_effect_assignment(assign);
      new_code.expression()=assign;
    }
    else
    {
      error().source_location=source_location;
      error() << "initialization of POD requires one argument, "
                 "but got " << operands.size() << eom;
      throw 0;
    }

    return new_code;
  }
  else if(tmp_type.id()==ID_union)
  {
    assert(0); // Todo: union
  }
  else if(tmp_type.id()==ID_struct)
  {
    exprt::operandst operands_tc=operands;

    for(exprt::operandst::iterator
      it=operands_tc.begin();
      it!=operands_tc.end();
      it++)
    {
      typecheck_expr(*it);
      add_implicit_dereference(*it);
    }

    const struct_typet &struct_type=
      to_struct_type(tmp_type);

    // set most-derived bits
    codet block(ID_block);
    for(std::size_t i=0; i < struct_type.components().size(); i++)
    {
      const irept &component=struct_type.components()[i];
      if(component.get(ID_base_name)!="@most_derived")
        continue;

      exprt member(ID_member, bool_typet());
      member.set(ID_component_name, component.get(ID_name));
      member.copy_to_operands(object_tc);
      member.add_source_location()=source_location;
      member.set(ID_C_lvalue, object_tc.get_bool(ID_C_lvalue));

      exprt val=false_exprt();

      if(!component.get_bool("from_base"))
        val=true_exprt();

      side_effect_exprt assign(ID_assign);
      assign.add_source_location()=source_location;
      assign.move_to_operands(member, val);
      typecheck_side_effect_assignment(assign);
      code_expressiont code_exp;
      code_exp.expression()=assign;
      block.move_to_operands(code_exp);
    }

    // enter struct scope
    cpp_save_scopet save_scope(cpp_scopes);
    cpp_scopes.set_scope(struct_type.get(ID_name));

    // find name of constructor
    const struct_typet::componentst &components=
      struct_type.components();

    irep_idt constructor_name;

    for(struct_typet::componentst::const_iterator
        it=components.begin();
        it!=components.end();
        it++)
    {
      const typet &type=it->type();

      if(!it->get_bool(ID_from_base) &&
         type.id()==ID_code &&
         type.find(ID_return_type).id()==ID_constructor)
      {
        constructor_name=it->get(ID_base_name);
        break;
      }
    }

    // there is always a constructor for non-PODs
    assert(constructor_name!="");

    irept cpp_name(ID_cpp_name);
    cpp_name.get_sub().push_back(irept(ID_name));
    cpp_name.get_sub().back().set(ID_identifier, constructor_name);
    cpp_name.get_sub().back().set(ID_C_source_location, source_location);

    side_effect_expr_function_callt function_call;
    function_call.add_source_location()=source_location;
    function_call.function().swap(static_cast<exprt&>(cpp_name));
    function_call.arguments().reserve(operands_tc.size());

    for(exprt::operandst::iterator
        it=operands_tc.begin();
        it!=operands_tc.end();
        it++)
      function_call.op1().copy_to_operands(*it);

    typecheck_side_effect_function_call(function_call);
    assert(function_call.get(ID_statement)==ID_temporary_object);

    exprt &initializer =
      static_cast<exprt &>(function_call.add(ID_initializer));

    assert(initializer.id()==ID_code &&
           initializer.get(ID_statement)==ID_expression);

    side_effect_expr_function_callt &func_ini=
      to_side_effect_expr_function_call(initializer.op0());

    exprt &tmp_this=func_ini.arguments().front();
    assert(tmp_this.id()==ID_address_of
           && tmp_this.op0().id()=="new_object");

    exprt address_of(ID_address_of, typet(ID_pointer));
    address_of.type().subtype()=object_tc.type();
    address_of.copy_to_operands(object_tc);
    tmp_this.swap(address_of);

    if(block.operands().empty())
      return to_code(initializer);
    else
    {
      block.move_to_operands(initializer);
      return block;
    }
  }
  else
    assert(false);

  codet nil;
  nil.make_nil();
  return nil;
}
Ejemplo n.º 16
0
void inl_gen::visit(const mfast::group_field_instruction* inst, void* pIndex)
{
  std::string name (cpp_name(inst));

  std::size_t index = pIndex == 0 ? 0 : *static_cast<std::size_t*>(pIndex);

  std::string cref_type_name = cref_scope_.str() + name + "_cref";
  std::string mref_type_name = mref_scope_.str() + name + "_mref";

  bool embed_only_dyn_tempateref = contains_only_templateref(inst);

  std::stringstream cref_strm;
  std::stringstream mref_strm;

  if (embed_only_dyn_tempateref) {
    cref_strm << "mfast::aggregate_cref((*this)[" << index << "])[0]";
    mref_strm << "mfast::aggregate_mref((*this)[" << index << "])[0]";
  }
  else {
    cref_strm << "(*this)[" << index << "]";
    mref_strm << "(*this)[" << index << "]";
  }

  if (pIndex) {
    out_ << "\ninline " << cref_type_name << "\n"
         << cref_scope_.str() << "get_" << name << "() const\n"
         << "{\n";
    if (inst->optional())
      out_ << "  if (" << "(*this)[" << index << "].absent())\n"
           << "    return " << cref_type_name << "(0, " << cref_type_name << "::instruction_cptr(0));\n";
    out_ << "  return static_cast<" << cref_type_name << ">(" << cref_strm.str() << ");\n"
         << "}\n\n"
         << "inline " << mref_type_name << "\n"
         << mref_scope_.str() << "set_" << name << "() const\n"
         << "{\n";
    if (inst->optional())
      out_ << "  this->field_storage(" << index << ")->present(true);\n";
    out_ << "  return " << mref_type_name << "("<< mref_strm.str() << ");\n"
         << "}\n\n";

    if (inst->optional()) {
      out_ << "inline\n"
           << "void\n"
           << mref_scope_.str() << "omit_" << name << "() const\n"
           << "{\n"
           << "  (*this)[" << index << "].omit();\n"
           << "}\n\n";
    }

    if (inst->ref_instruction()) {
      out_ << "inline void\n"
           << mref_scope_.str() << "link_" << name << "(const " << mref_type_name << "& ref) const\n"
           << "{\n"
           << "  this->link_group_at(" << index << ", ref);\n"
           << "}\n\n"
           << "inline void\n"
           << mref_scope_.str() << "unlink_" << name << "() const\n"
           << "{\n"
           << "  this->unlink_group_at(" << index << ");\n"
           << "}\n\n";
    }
  }

  if (inst->ref_instruction() == 0 && !embed_only_dyn_tempateref) {

    out_ << "inline\n"
         << cref_type_name << "::"<< name << "_cref()\n"
         << "  : base_type(0, 0)\n"
         << "{\n"
         << "}\n\n"
         << "template <typename T>"
         << "inline\n"
         << cref_type_name << "::" << name << "_cref(\n"
         << "  typename boost::enable_if<boost::is_same<typename T::cref_type, " << name << "_cref>, const mfast::value_storage*>::type storage_array,\n"
         << "  const T* instruction)\n"
         << "  : base_type(storage_array, instruction)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << cref_type_name << "::"<< name << "_cref(\n"
         << "  const mfast::field_cref& other)\n"
         << "  : base_type(other)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << mref_type_name << "::"<< name << "_mref()\n"
         << "  : base_type(0, 0, 0)\n"
         << "{\n"
         << "}\n\n"
         << "template <typename T>"
         << "inline\n"
         << mref_type_name << "::" << name << "_mref(\n"
         << "  mfast::allocator* alloc,\n"
         << "  typename boost::enable_if<boost::is_same<typename T::cref_type, " << name << "_cref>, mfast::value_storage*>::type storage_array,\n"
         << "  const T*          instruction)\n"
         << "  : base_type(alloc, storage_array, instruction)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << mref_type_name << "::"<< name << "_mref(\n"
         << "  const mfast::field_mref_base& other)\n"
         << "  : base_type(other)\n"
         << "{\n"
         << "}\n\n";

    if (!pIndex)
    {
      out_ << "inline\n"
           << name << "::" << name << "(\n"
           << "  mfast::allocator* alloc)\n"
           << "  : base_type(alloc, instruction(), this->data())\n"
           << "{\n"
           << "}\n\n"
           << "inline\n"
           << name << "::" << name << "(\n"
           << "  const " << name << "_cref& other,\n"
           << "  mfast::allocator* alloc)\n"
           << "  : base_type(alloc, instruction(), this->data(), other.field_storage(0))\n"
           << "{\n"
           << "}\n\n"
           << "inline "<< name << "::cref_type\n"
           << name << "::ref() const\n"
           << "{\n"
           << "  return " << name << "::cref_type(my_storage_.of_group.content_, instruction());\n"
           << "}\n\n"
           << "inline "<< name << "::cref_type\n"
           << name << "::cref() const\n"
           << "{\n"
           << "  return " << name << "::cref_type(my_storage_.of_group.content_, instruction());\n"
           << "}\n\n"
           << "inline "<< name << "::mref_type\n"
           << name << "::ref()\n"
           << "{\n"
           << "  return " << name << "::mref_type(alloc_, my_storage_.of_group.content_, instruction());\n"
           << "}\n\n"
           << "inline "<< name << "::mref_type\n"
           << name << "::mref()\n"
           << "{\n"
           << "  return " << name << "::mref_type(alloc_, my_storage_.of_group.content_, instruction());\n"
           << "}\n\n";
    }

    traverse(inst, "");
  }
}
Ejemplo n.º 17
0
void inl_gen::visit(const mfast::enum_field_instruction* inst, void* pIndex)
{
  std::string name (cpp_name(inst));
  std::string cref_type_name = cref_scope_.str() + name + "_cref";
  std::string mref_type_name = mref_scope_.str() + name + "_mref";


  if (inst->ref_instruction() == 0) {

    out_ << "inline\n"
         << cref_type_name << "::"<< name << "_cref(\n"
         << "  const mfast::value_storage*   storage,\n"
         << "  " << cref_type_name << "::instruction_cptr instruction)\n"
         << "  : base_type(storage, instruction)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << cref_type_name << "::"<< name << "_cref(\n"
         << "  const mfast::field_cref& other)\n"
         << "  : base_type(other)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << mref_type_name << "::"<< name << "_mref(\n"
         << "  mfast::allocator*      alloc,\n"
         << "  mfast::value_storage*  storage,\n"
         << "  " << mref_type_name << "::instruction_cptr instruction)\n"
         << "  : base_type(alloc, storage, instruction)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << mref_type_name << "::"<< name << "_mref(\n"
         << "  const mfast::field_mref_base& other)\n"
         << "  : base_type(other)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << cref_type_name << "::element_type\n"
         << cref_type_name << "::value() const\n"
         << "{\n"
         << "  return static_cast<" << name << "::element>(base_type::value());\n"
         << "}\n\n";


    for (uint64_t i = 0; i < inst->num_elements_; ++i)
    {

      std::string element_name = cpp_name(inst->elements_[i]);

      out_ << "inline\n"
           << "bool " << cref_type_name << "::is_" << element_name << "() const\n"
           << "{\n"
           << "  return this->value() == " << name << "::" <<  element_name << ";\n"
           << "}\n\n"
           << "inline\n"
           << "void " << mref_type_name << "::as_" << element_name << "() const\n"
           << "{\n"
           << "  return this->as(" << name << "::" <<  element_name << ");\n"
           << "}\n\n";

    }
  }


  gen_accessors(inst, name, cref_type_name, mref_type_name, pIndex);
}
Ejemplo n.º 18
0
void inl_gen::visit(const mfast::template_instruction* inst, void*)
{
  // if (inst->subinstructions().size() == 0)
  //   return;

  std::string name (cpp_name(inst));

  out_ << "inline\n"
       << name << "_cref::" << name << "_cref()\n"
       << "  : base_type(0, 0)\n"
       << "{\n"
       << "}\n\n"
       << "template <typename T>"
       << "inline\n"
       << name << "_cref::" << name << "_cref(\n"
       << "  typename boost::enable_if<boost::is_same<typename T::cref_type, " << name << "_cref>, const mfast::value_storage*>::type storage_array,\n"
       << "  const T* instruction)\n"
       << "  : base_type(storage_array, instruction)\n"
       << "{\n"
       << "}\n\n"
       << "inline\n"
       << name << "_cref::" << name << "_cref(\n"
       << "  const mfast::message_cref& other)\n"
       << "  : base_type(other)\n"
       << "{\n"
       << "}\n\n"
       << "inline\n"
       << name << "_cref::" << name << "_cref(\n"
       << "  const mfast::field_cref& other)\n"
       << "  : base_type(mfast::field_cref_core_access::storage_of(other)->of_group.content_,\n"
       << "              static_cast<instruction_cptr>(other.instruction()))\n"
       << "{\n"
       << "}\n\n"
       << "inline\n"
       << name << "_mref::" << name << "_mref()\n"
       << "  : base_type(0, 0, 0)\n"
       << "{\n"
       << "}\n\n"
       << "template <typename T>"
       << "inline\n"
       << name << "_mref::" << name << "_mref(\n"
       << "  mfast::allocator* alloc,\n"
       << "  typename boost::enable_if<boost::is_same<typename T::cref_type, " << name << "_cref>, mfast::value_storage*>::type storage_array,\n"
       << "  const T*          instruction)\n"
       << "  : base_type(alloc, storage_array, instruction)\n"
       << "{\n"
       << "}\n\n"
       << "inline\n"
       << name << "_mref::" << name << "_mref(\n"
       << "  const mfast::message_mref& other)\n"
       << "  : base_type(other)\n"
       << "{\n"
       << "}\n\n"
       << "inline\n"
       << name << "_mref::" << name << "_mref(\n"
       << "  const mfast::field_mref_base& other)\n"
       << "  : base_type(other.allocator(),\n"
       << "              mfast::field_mref_core_access::storage_of(other)->of_group.content_,\n"
       << "              static_cast<instruction_cptr>(other.instruction()))\n"
       << "{\n"
       << "}\n\n"
       << "inline\n"
       << name << "::" << name << "(\n"
       << "  mfast::allocator* alloc)\n"
       << "  : base_type(alloc, instruction(), this->data())\n"
       << "{\n"
       << "}\n\n"
       << "inline\n"
       << name << "::" << name << "(\n"
       << "  const " << name << "_cref& other,\n"
       << "  mfast::allocator* alloc)\n"
       << "  : base_type(alloc, instruction(), this->data(), other.field_storage(0))\n"
       << "{\n"
       << "}\n\n"
       << "inline "<< name << "::cref_type\n"
       << name << "::ref() const\n"
       << "{\n"
       << "  return " << name << "::cref_type(my_storage_.of_group.content_, instruction());\n"
       << "}\n\n"
       << "inline "<< name << "::cref_type\n"
       << name << "::cref() const\n"
       << "{\n"
       << "  return " << name << "::cref_type(my_storage_.of_group.content_, instruction());\n"
       << "}\n\n"
       << "inline "<< name << "::mref_type\n"
       << name << "::ref()\n"
       << "{\n"
       << "  return " << name << "::mref_type(alloc_, my_storage_.of_group.content_, instruction());\n"
       << "}\n\n"
       << "inline "<< name << "::mref_type\n"
       << name << "::mref()\n"
       << "{\n"
       << "  return " << name << "::mref_type(alloc_, my_storage_.of_group.content_, instruction());\n"
       << "}\n\n";

  this->traverse(inst, "");
}
Ejemplo n.º 19
0
void inl_gen::visit(const mfast::sequence_field_instruction* inst, void* pIndex)
{
  std::string name (cpp_name(inst));

  std::string cref_type_name = cref_scope_.str() + name + "_cref";
  std::string mref_type_name = mref_scope_.str() + name + "_mref";

  gen_accessors(inst, name, cref_type_name, mref_type_name, pIndex);

  const mfast::field_instruction* element_instruction = get_element_instruction(inst);

  if (inst->ref_instruction() == 0 && element_instruction==0) {
    out_ << "inline\n"
         << cref_scope_.str() << name << "_element_cref::"<< name << "_element_cref(\n"
         << "  const mfast::value_storage*   storage,\n"
         << "  " << cref_scope_.str() << name << "_element_cref::instruction_cptr instruction)\n"
         << "  : base_type(storage, instruction)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << mref_scope_.str() << name << "_element_mref::"<< name << "_element_mref(\n"
         << "  mfast::allocator*               alloc,\n"
         << "  mfast::value_storage*         storage,\n"
         << "  " << mref_scope_.str() << name << "_element_mref::instruction_cptr instruction)\n"
         << "  : base_type(alloc,storage, instruction)\n"
         << "{\n"
         << "}\n\n";

    traverse(inst, "_element");
  }

  if (pIndex == 0)
  {
    out_ << "inline\n"
         << name << "::" << name << "(\n"
         << "  mfast::allocator* alloc)\n"
         << "  : base_type(alloc, instruction(), 0)\n"
         << "{\n"
         << "}\n\n"
         << "inline\n"
         << name << "::" << name << "(\n"
         << "  const " << name << "_cref& other,\n"
         << "  mfast::allocator* alloc)\n"
         << "  : base_type(reinterpret_cast<const mfast::sequence_cref&>(other), alloc)\n"
         << "{\n"
         << "}\n\n"
         << "inline "<< name << "::cref_type\n"
         << name << "::ref() const\n"
         << "{\n"
         << "  return " << name << "::cref_type(&my_storage_, instruction());\n"
         << "}\n\n"
         << "inline "<< name << "::cref_type\n"
         << name << "::cref() const\n"
         << "{\n"
         << "  return " << name << "::cref_type(&my_storage_, instruction());\n"
         << "}\n\n"
         << "inline "<< name << "::mref_type\n"
         << name << "::ref()\n"
         << "{\n"
         << "  return " << name << "::mref_type(alloc_, &my_storage_, instruction());\n"
         << "}\n\n"
         << "inline "<< name << "::mref_type\n"
         << name << "::mref()\n"
         << "{\n"
         << "  return " << name << "::mref_type(alloc_, &my_storage_, instruction());\n"
         << "}\n\n";
  }

}