X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=scripts%2Fparse3.awk;h=6bd586756ab669503a595ebf8b0f5bbe38add52f;hb=refs%2Ftags%2FV5_1_2rc2;hp=0d8a22b22eb760a9380ccefc85f85f7dff4ac449;hpb=eb23d5150f3cd1715528ba0a4668b93a7700591f;p=tools%2Fhxx2salome.git diff --git a/scripts/parse3.awk b/scripts/parse3.awk index 0d8a22b..6bd5867 100644 --- a/scripts/parse3.awk +++ b/scripts/parse3.awk @@ -1,4 +1,8 @@ # This awk program contains the type mapping tables - and the treatments +# -- +# Copyright (C) CEA, EDF +# Author : Nicolas Crouzet (CEA) +# -- # for code generation # BEGIN { @@ -33,14 +37,19 @@ BEGIN { idl_arg_type["std::string&"]="out string" idl_arg_type["const MEDMEM::MESH&"]="in SALOME_MED::MESH" idl_arg_type["const MEDMEM::MESH*"]="in SALOME_MED::MESH" + idl_arg_type["const MEDMEM::SUPPORT&"]="in SALOME_MED::SUPPORT" + idl_arg_type["const MEDMEM::SUPPORT*"]="in SALOME_MED::SUPPORT" idl_arg_type["const MEDMEM::FIELD*"]="in SALOME_MED::FIELDDOUBLE" idl_arg_type["const MEDMEM::FIELD&"]="in SALOME_MED::FIELDDOUBLE" - idl_arg_type["const std::vector&"]="in SALOME::SenderDouble" idl_arg_type["MEDMEM::FIELD*&"]="out SALOME_MED::FIELDDOUBLE" + idl_arg_type["const std::vector&"]="in SALOME::SenderDouble" + idl_arg_type["const std::vector >&"]="in SALOME::Matrix" + idl_arg_type["std::vector*&"]="out SALOME::SenderDouble" idl_arg_type["const MEDMEM::FIELD*"]="in SALOME_MED::FIELDINT" idl_arg_type["const MEDMEM::FIELD&"]="in SALOME_MED::FIELDINT" - idl_arg_type["const std::vector&"]="in SALOME::SenderInt" idl_arg_type["MEDMEM::FIELD*&"]="out SALOME_MED::FIELDINT" + idl_arg_type["const std::vector&"]="in SALOME::SenderInt" + idl_arg_type["std::vector*&"]="out SALOME::SenderInt" # # # mapping for returned types @@ -59,11 +68,13 @@ BEGIN { idl_rtn_type["MEDMEM::MESH&"]="SALOME_MED::MESH" idl_rtn_type["MEDMEM::MESH*"]="SALOME_MED::MESH" idl_rtn_type["const MEDMEM::MESH*"]="SALOME_MED::MESH" + idl_rtn_type["MEDMEM::SUPPORT*"]="SALOME_MED::SUPPORT" idl_rtn_type["const MEDMEM::FIELD*"]="SALOME_MED::FIELDDOUBLE" idl_rtn_type["MEDMEM::FIELD*"]="SALOME_MED::FIELDDOUBLE" idl_rtn_type["MEDMEM::FIELD&"]="SALOME_MED::FIELDDOUBLE" idl_rtn_type["const MEDMEM::FIELD&"]="SALOME_MED::FIELDDOUBLE" idl_rtn_type["std::vector*"]="SALOME::SenderDouble" + idl_rtn_type["std::vector >*"]="SALOME::Matrix" idl_rtn_type["const MEDMEM::FIELD*"]="SALOME_MED::FIELDINT" idl_rtn_type["MEDMEM::FIELD*"]="SALOME_MED::FIELDINT" idl_rtn_type["MEDMEM::FIELD&"]="SALOME_MED::FIELDINT" @@ -73,7 +84,6 @@ BEGIN { # # Corba mapping table (for argument's types and returned types) # -# CNC commented types are not yet implemented idl_impl_hxx["in long"]="CORBA::Long" idl_impl_hxx["in double"]="CORBA::Double" idl_impl_hxx["in float"]="CORBA::Float" @@ -87,20 +97,26 @@ BEGIN { idl_impl_hxx["out unsigned long"]="CORBA::ULong_out" idl_impl_hxx["out string"]="CORBA::String_out" idl_impl_hxx["in SALOME_MED::MESH"]="SALOME_MED::MESH_ptr" + idl_impl_hxx["in SALOME_MED::SUPPORT"]="SALOME_MED::SUPPORT_ptr" idl_impl_hxx["in SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_ptr" - idl_impl_hxx["in SALOME::SenderDouble"]="SALOME::SenderDouble_ptr" idl_impl_hxx["out SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_out" + idl_impl_hxx["in SALOME::SenderDouble"]="SALOME::SenderDouble_ptr" + idl_impl_hxx["out SALOME::SenderDouble"]="SALOME::SenderDouble_out" + idl_impl_hxx["in SALOME::Matrix"]="SALOME::Matrix_ptr" idl_impl_hxx["in SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_ptr" - idl_impl_hxx["in SALOME::SenderInt"]="SALOME::SenderInt_ptr" idl_impl_hxx["out SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_out" + idl_impl_hxx["in SALOME::SenderInt"]="SALOME::SenderInt_ptr" + idl_impl_hxx["out SALOME::SenderInt"]="SALOME::SenderInt_out" idl_impl_hxx["void"]="void" idl_impl_hxx["long"]="CORBA::Long" idl_impl_hxx["double"]="CORBA::Double" idl_impl_hxx["unsigned long"]="CORBA::ULong" idl_impl_hxx["string"]="char*" idl_impl_hxx["SALOME_MED::MESH"]="SALOME_MED::MESH_ptr" + idl_impl_hxx["SALOME_MED::SUPPORT"]="SALOME_MED::SUPPORT_ptr" idl_impl_hxx["SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_ptr" idl_impl_hxx["SALOME::SenderDouble"]="SALOME::SenderDouble_ptr" + idl_impl_hxx["SALOME::Matrix"]="SALOME::Matrix_ptr" idl_impl_hxx["SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_ptr" idl_impl_hxx["SALOME::SenderInt"]="SALOME::SenderInt_ptr" # @@ -124,16 +140,25 @@ BEGIN { cpp_impl_a["std::string&"]="std::string _%s;\n" cpp_impl_a["const MEDMEM::MESH&"]="\tMEDMEM::MESHClient* _%s = new MEDMEM::MESHClient(%s);\n" # MESHClient cannot be created on the stack (private constructor), so we create it on the heap and dereference it later (in treatment 4) cpp_impl_a["const MEDMEM::MESH*"]="\tMEDMEM::MESHClient* _%s = new MEDMEM::MESHClient(%s);\n" + cpp_impl_a["const MEDMEM::SUPPORT&"]="\tMEDMEM::SUPPORTClient* _%s = new MEDMEM::SUPPORTClient(%s);\n" # SUPPORTClient cannot be created on the stack (protected destructor), so we create it on the heap and dereference it later (in treatment 4) + cpp_impl_a["const MEDMEM::SUPPORT*"]="\tMEDMEM::SUPPORTClient* _%s = new MEDMEM::SUPPORTClient(%s);\n" cpp_impl_a["MEDMEM::FIELD*&"]="\tMEDMEM::FIELD* _%s;\n" - cpp_impl_a["const MEDMEM::FIELD*"]="\tstd::auto_ptr > _%s ( new MEDMEM::FIELDClient(%s) );\n" - cpp_impl_a["const MEDMEM::FIELD&"]="\tMEDMEM::FIELDClient _%s(%s);\n" - cpp_impl_a["const std::vector&"]="\tlong _size;\n\tdouble *_value = ReceiverFactory::getValue(%s,_size);\n"\ - "\tstd::vector _%s(_value,_value+_size);\n\tdelete [] _value;" + cpp_impl_a["const MEDMEM::FIELD*"]="\tstd::auto_ptr > _%s ( new MEDMEM::FIELDClient(%s) );\n" + cpp_impl_a["const MEDMEM::FIELD&"]="\tMEDMEM::FIELDClient _%s(%s);\n" + cpp_impl_a["const std::vector&"]="\tlong _%s_size;\n\tdouble *_%s_value = ReceiverFactory::getValue(%s,_%s_size);\n"\ + "\tstd::vector _%s(_%s_value,_%s_value+_%s_size);\n\tdelete [] _%s_value;" + cpp_impl_a["std::vector*&"]="\tstd::vector* _%s;\n" + cpp_impl_a["const std::vector >&"]="\tMatrixClient _%s_client;\n\tint _%s_nbRow;\n\tint _%s_nbCol;\n"\ + "\tdouble* _%s_tab = _%s_client.getValue(%s,_%s_nbCol,_%s_nbRow);\n\tstd::vector > _%s(_%s_nbRow);\n"\ + "\tfor (int i=0; i!=_%s_nbRow; ++i)\n\t{\n\t _%s[i].resize(_%s_nbCol);\n"\ + "\t std::copy(_%s_tab+_%s_nbCol*i,_%s_tab+_%s_nbCol*(i+1), _%s[i].begin());\n\t}\n\tdelete [] _%s_tab;\n" cpp_impl_a["MEDMEM::FIELD*&"]="\tMEDMEM::FIELD* _%s;\n" cpp_impl_a["const MEDMEM::FIELD*"]="\tstd::auto_ptr > _%s ( new MEDMEM::FIELDClient(%s) );\n" cpp_impl_a["const MEDMEM::FIELD&"]="\tMEDMEM::FIELDClient _%s(%s);\n" - cpp_impl_a["const std::vector&"]="\tlong _size;\n\tint *_value = ReceiverFactory::getValue(%s,_size);\n"\ - "\tstd::vector _%s(_value,_value+_size);\n\tdelete [] _value;" + cpp_impl_a["const std::vector&"]="\tlong _%s_size;\n\tint *_%s_value = ReceiverFactory::getValue(%s,_%s_size);\n"\ + "\tstd::vector _%s(_%s_value,_%s_value+_%s_size);\n\tdelete [] _%s_value;" + cpp_impl_a["std::vector*&"]="\tstd::vector* _%s;\n" + # # # table for c++ code generation : returned value processing @@ -161,20 +186,29 @@ BEGIN { cpp_impl_b["const MEDMEM::MESH*"]=\ "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast(_rtn_cpp));\n"\ "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n" + cpp_impl_b["MEDMEM::SUPPORT*"]=\ + "\tMEDMEM::SUPPORT_i * _rtn_support_i = new MEDMEM::SUPPORT_i(_rtn_cpp);\n"\ + "\tSALOME_MED::SUPPORT_ptr _rtn_ior = _rtn_support_i->_this();\n" cpp_impl_b["const MEDMEM::FIELD*"]=\ - "\tMEDMEM::FIELDDOUBLE_i * _rtn_field_i = new MEDMEM::FIELDDOUBLE_i(const_cast*>(_rtn_cpp),false);\n"\ + "\tMEDMEM::FIELDTEMPLATE_I * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I(const_cast*>(_rtn_cpp),false);\n"\ "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n" cpp_impl_b["MEDMEM::FIELD*"]=\ - "\tMEDMEM::FIELDDOUBLE_i * _rtn_field_i = new MEDMEM::FIELDDOUBLE_i(_rtn_cpp,true);\n"\ + "\tMEDMEM::FIELDTEMPLATE_I * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I(_rtn_cpp,true);\n"\ "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n" cpp_impl_b["MEDMEM::FIELD&"]=\ - "\tMEDMEM::FIELDDOUBLE_i * _rtn_field_i = new MEDMEM::FIELDDOUBLE_i(&_rtn_cpp,false);\n"\ + "\tMEDMEM::FIELDTEMPLATE_I * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I(&_rtn_cpp,false);\n"\ "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n" cpp_impl_b["const MEDMEM::FIELD&"]=\ - "\tMEDMEM::FIELDDOUBLE_i * _rtn_field_i = new MEDMEM::FIELDDOUBLE_i(const_cast*>(&_rtn_cpp),false);\n"\ + "\tMEDMEM::FIELDTEMPLATE_I * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I(const_cast*>(&_rtn_cpp),false);\n"\ "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n" cpp_impl_b["std::vector*"]=\ "\tSALOME::SenderDouble_ptr _rtn_ior = SenderFactory::buildSender(*this,&(*_rtn_cpp)[0],(*_rtn_cpp).size(),true);\n" + cpp_impl_b["std::vector >*"]=\ + "\tint _rtn_cpp_i=(*_rtn_cpp).size();\n\tint _rtn_cpp_j=(*_rtn_cpp)[0].size();\n"\ + "\tdouble* _rtn_tab = new double[_rtn_cpp_i*_rtn_cpp_j];\n"\ + "\tfor (int i=0; i!=_rtn_cpp_i; ++i)\n\t std::copy((*_rtn_cpp)[i].begin(),(*_rtn_cpp)[i].end(),_rtn_tab+i*_rtn_cpp_j);\n"\ + "\tSALOME_Matrix_i* _rtn_matrix_i = new SALOME_Matrix_i(*this,_rtn_tab,_rtn_cpp_i,_rtn_cpp_j,true);\n"\ + "\tSALOME::Matrix_ptr _rtn_ior = _rtn_matrix_i->_this();\n\tdelete _rtn_cpp;\n" cpp_impl_b["const MEDMEM::FIELD*"]=\ "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast*>(_rtn_cpp),false);\n"\ "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n" @@ -195,24 +229,30 @@ BEGIN { # table for c++ code generation : out parameters processing and removeRef for reference counted objects # cpp_impl_c["MEDMEM::FIELD*&"]=\ - "\tMEDMEM::FIELDDOUBLE_i * %s_ior = new MEDMEM::FIELDDOUBLE_i(_%s, true);\n"\ + "\tMEDMEM::FIELDTEMPLATE_I * %s_ior = new MEDMEM::FIELDTEMPLATE_I(_%s, true);\n"\ "\t%s = %s_ior->_this();\n" cpp_impl_c["MEDMEM::FIELD*&"]=\ "\tMEDMEM::FIELDINT_i * %s_ior = new MEDMEM::FIELDINT_i(_%s, true);\n"\ "\t%s = %s_ior->_this();\n" + cpp_impl_c["std::vector*&"]=\ + "\t%s = SenderFactory::buildSender(*this,&(*_%s)[0],(*_%s).size(),true);\n" + cpp_impl_c["std::vector*&"]=\ + "\t%s = SenderFactory::buildSender(*this,&(*_%s)[0],(*_%s).size(),true);\n" cpp_impl_c["std::string&"]="\t%s = CORBA::string_dup(_%s.c_str());\n" - cpp_impl_c["int&"]="\t%s = _%s" - cpp_impl_c["double&"]="\t%s = _%s" - cpp_impl_c["float&"]="\t%s = _%s" - cpp_impl_c["long&"]="\t%s = _%s" - cpp_impl_c["short&"]="\t%s = _%s" - cpp_impl_c["unsigned&"]="\t%s = _%s" + cpp_impl_c["int&"]="\t%s = _%s;\n" + cpp_impl_c["double&"]="\t%s = _%s;\n" + cpp_impl_c["float&"]="\t%s = _%s;\n" + cpp_impl_c["long&"]="\t%s = _%s;\n" + cpp_impl_c["short&"]="\t%s = _%s;\n" + cpp_impl_c["unsigned&"]="\t%s = _%s;\n" cpp_impl_c["const MEDMEM::MESH&"]="\t_%s->removeReference();\n" cpp_impl_c["const MEDMEM::MESH*"]="\t_%s->removeReference();\n" + cpp_impl_c["const MEDMEM::SUPPORT&"]="\t_%s->removeReference();\n" + cpp_impl_c["const MEDMEM::SUPPORT*"]="\t_%s->removeReference();\n" # # # record sep is ");\n" whith blanks all around, and optional "(" at the beginning - RS="[(]?[ \t]*)[ \t]*;[ \t]*\n" + RS="[(]?[ \t]*[)][ \t]*(const)?[ \t]*[;][ \t]*[\n]" FS="[ \t]*[(,][ \t]*" # field sep is either "(" or "," surrounded by blanks } @@ -308,8 +348,7 @@ BEGIN { # generate the C++ implementation of component (cxx file) # { - - + # a) generate the function declaration + macro declarations func_name=class_name"_i::"name[1] printf "%s %s(",idl_impl_hxx[idl_rtn_type[type[1]]],func_name >> cxx_file if ( NF >= 2 ){ # if there is arguments, print them @@ -319,12 +358,15 @@ BEGIN { } printf ")\n{\n\tbeginService(\"%s\");\n\tBEGIN_OF(\"%s\");\n",func_name,func_name >> cxx_file + # b) generate the argument processing part if ( NF >= 2 ){ printf "//\tArguments processing\n" >> cxx_file for (i=2; i<=NF; i++) - printf cpp_impl_a[type[i]],name[i],name[i] >> cxx_file + printf cpp_impl_a[type[i]],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],\ + name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i] >> cxx_file } + # c) generate the call to the c++ component if ( type[1] == "void" ) # if return type is void, the call syntax is different. printf "//\tCall cpp component\n\tcppCompo_->%s(",name[1] >> cxx_file else @@ -336,13 +378,15 @@ BEGIN { pre="" if ( cpp_impl_a[type[i]] ~ "auto_ptr" ) post=".get()" # for auto_ptr argument, retrieve the raw pointer behind - if ( type[i] == "const MEDMEM::MESH&" ) + if ( type[i] == "const MEDMEM::MESH&" || type[i] == "const MEDMEM::SUPPORT&" ) pre="*" # we cannot create MESHClient on the stack (private constructor), so we create it on the heap and dereference it if ( i < NF ) post=post"," # separator between arguments printf " %s_%s%s",pre,name[i],post >> cxx_file } } + + # d) generate the post_processing of returned and out parameters printf ");\n//\tPost-processing & return\n" >> cxx_file for (i=2; i<=NF; i++) printf cpp_impl_c[type[i]],name[i],name[i],name[i],name[i] >> cxx_file # process for out parameters