1 # Copyright (C) 2009-2013 EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from gener import Component
21 from cppcompo import CPPComponent
24 archi = platform.architecture()[0]
27 f77Types = {"double":"double *", "long":"int *", "string":"const char *"}
29 f77Types = {"double":"double *", "long":"long *", "string":"const char *"}
31 class F77Component(CPPComponent):
33 A :class:`F77Component` instance represents a Fortran SALOME component with services given as a list of :class:`Service`
34 instances with the parameter *services*.
36 :param name: gives the name of the component.
38 :param services: the list of services (:class:`Service`) of the component.
39 :param kind: If it is given and has the value "exe", the component will be built as a standalone
40 component (executable or shell script). The default is to build the component as a dynamic library.
41 :param libs: gives all the libraries options to add when linking the generated component (-L...).
42 :param rlibs: gives all the runtime libraries options to add when linking the generated component (-R...).
43 :param sources: gives all the external source files to add in the compilation step (list of paths).
44 :param exe_path: is only used when kind is "exe" and gives the path to the standalone component.
46 For example, the following call defines a Fortran component named "mycompo" with one service s1 (it must have been defined before).
47 This component is implemented as a dynamic library linked with a user's library "mylib"::
49 >>> c1 = module_generator.F77Component('mycompo', services=[s1,],
50 libs="-lmylib -Lmydir")
53 def __init__(self, name, services=None, libs="", rlibs="",
54 kind="lib", exe_path=None, sources=None):
55 CPPComponent.__init__(self, name, services, libs=libs, rlibs=rlibs,
56 kind=kind, exe_path=exe_path, sources=sources)
60 """generate definitions (defs attribute of services) et bodys (body attribute of services)"""
61 for serv in self.services:
64 if serv.instream or serv.outstream:
65 params = ["void *compo"]
67 for name, typ in serv.inport:
68 if typ == "file":continue #files are not passed through service interface
70 params.append("const STR_PSTR(%s)"%name)
71 strparams.append("STR_PLEN(%s)"%name)
73 params.append("%s %s" % (f77Types[typ], name))
74 for name, typ in serv.outport:
75 if typ == "file":continue #files are not passed through service interface
77 params.append("const STR_PSTR(%s)"%name)
78 strparams.append("STR_PLEN(%s)"%name)
80 params.append("%s %s" % (f77Types[typ], name))
81 args = ','.join(params)+" " + " ".join(strparams)
82 serv.defs = serv.defs+'\nextern "C" void F_FUNC(%s,%s)(%s);' % (serv.name.lower(), serv.name.upper(), args)
86 if serv.instream or serv.outstream:
87 params = ["&component"]
90 #length allocated for out string
92 for name, typ in serv.inport:
93 if typ == "file":continue #files are not passed through service interface
95 params.append("STR_CPTR(%s)" % name)
96 strparams.append("STR_CLEN(%s)"%name)
98 params.append("&%s" % name)
99 for name, typ in serv.outport:
100 if typ == "file":continue #files are not passed through service interface
102 params.append("STR_CPTR(%s.ptr())" % name)
103 strparams.append("STR_CLEN(%s.ptr())"%name)
104 strallocs.append('%s=CORBA::string_dup("%s");' %(name, " "*lstr))
106 params.append("&%s" % name)
107 serv.body = '\n'.join(strallocs)+'\n'+serv.body
108 args = ','.join(params)+" " + " ".join(strparams)
109 serv.body = serv.body+"\n F_CALL(%s,%s)(%s);" % (serv.name.lower(), serv.name.upper(), args)
111 def makeCompo(self, gen):
112 """build a dictionary that defines component files
113 dictionary key = file name
114 dictionary value = file content or dictionary defining subdirectory content
117 return CPPComponent.makeCompo(self, gen)