__init__.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- python -*-
00003 #
00004 #  @file omniidl_be/doil/__init__.py
00005 #  @brief doil backend for omniidl
00006 #  @date $Date$
00007 #  @author Noriaki Ando <n-ando@aist.go.jp>
00008 # 
00009 #  Copyright (C) 2008
00010 #      Task-intelligence Research Group,
00011 #      Intelligent Systems Research Institute,
00012 #      National Institute of
00013 #          Advanced Industrial Science and Technology (AIST), Japan
00014 #      All rights reserved.
00015 # 
00016 #  $Id$
00017 # 
00018 
00019 #   Entrypoint to the doil backend
00020 
00021 # modules from omniidl
00022 from omniidl import idlast, idlvisitor, idlutil
00023 
00024 # module from omniidl_be.cxx
00025 from omniidl_be.cxx import support, ast, id
00026 
00027 # module from omniidl_be.doil
00028 from omniidl_be.doil import util, config
00029 
00030 import re, sys, os.path
00031 
00032 cpp_args = ["-D__OMNIIDL_CXX__"]
00033 usage_string = """\
00034   -Wbm=<mapfile>  Specify type mapping rule file (mandatory)
00035   -Wbi=<include>  Specify include files
00036   -Wbimplicit     Process included IDLs implicitly
00037   -Wbinterface    Generate doil C++ interface header
00038   -Wbcorbaservant Generate doil servant class for CORBA
00039   -Wbcorbaadapter Generate doil adapter class for CORBA
00040   -Wbcorbaproxy   Generate doil proxy class for CORBA
00041   -Wbiceslice     Generate Ice slice file from CORBA IDL
00042   -Wbiceservant   Generate doil servant class for Ice
00043   -Wbiceadapter   Generate doil adapter class for Ice
00044   -Wbiceproxy     Generate doil proxy class for Ice
00045 
00046 [ options for servant class ]
00047   -Wbss=<suffix>  Specify suffix for generated servant files [default Servant]
00048   -Wbsp=<prefix>  Specify prefix for generated servant files [default None]
00049   -Wbsns=<ns>     Specify namespsace of generated servant class [default None]
00050   -Wbsdir=<ns>    Specify directory of generated servant header [default None]
00051 
00052 [ options for adapter class ]
00053   -Wbas=<suffix>  Specify suffix for generated adapter class [default Adapter]
00054   -Wbap=<prefix>  Specify prefix for generated adapter class [default None]
00055   -Wbans=<ns>     Specify namespsace of generated adapter class [default None]
00056   -Wbadir=<ns>    Specify directory of generated adapter header [default None]
00057 
00058 [ options for proxy class ]
00059   -Wbps=<suffix>  Specify suffix for generated proxy class [default Proxy]
00060   -Wbpp=<prefix>  Specify prefix for generated proxy class [default None]
00061   -Wbpns=<ns>     Specify namespsace of generated proxy class [default None]
00062   -Wbpdir=<ns>    Specify directory of generated proxy header [default None]
00063 
00064 [ options for interface class ]
00065   -Wbis=<suffix>  Specify suffix for local interface class [default None]
00066   -Wbip=<prefix>  Specify prefix for local interface class [default I]
00067   -Wbins=<ns>     Specify namespsace of local interface class [default None]
00068   -Wbidir=<ns>    Specify directory of local interface class [default None]
00069 
00070 """
00071 
00072 # Encountering an unknown AST node will cause an AttributeError exception
00073 # to be thrown in one of the visitors. Store a list of those not-supported
00074 # so we can produce a friendly error message later.
00075 AST_unsupported_nodes = [ "Native", "StateMember", "Factory", "ValueForward",
00076                           "ValueBox", "ValueAbs", "Value" ]
00077 
00078 def process_args(args):
00079     for arg in args:
00080         if arg == "d":
00081             config.state['Debug']                  = True
00082         elif arg[:2] == "m=":
00083             config.state['MappingFile']            = arg[2:]
00084         elif arg[:2] == "i=":
00085             config.state['IncludeHeaders'].append(arg[2:])
00086         # generator options
00087         elif arg == "implicit":
00088             config.state['ImplicitInclude']        = True
00089         elif arg == "interface":
00090             config.state['Interface']              = True
00091         elif arg == "corbaservant":
00092             config.state['CORBAServant']           = True
00093         elif arg == "corbaadapter":
00094             config.state['CORBAAdapter']           = True
00095         elif arg == "corbaproxy":
00096             config.state['CORBAProxy']             = True
00097         elif arg == "iceslice":
00098             config.state['IceSlice']               = True
00099         elif arg == "iceservant":
00100             config.state['IceServant']             = True
00101         elif arg == "iceadapter":
00102             config.state['IceAdapter']             = True
00103         elif arg == "iceproxy":
00104             config.state['IceProxy']               = True
00105         # for servant
00106         elif arg[:3] == "ss=":
00107             config.state['ServantSuffix']          = arg[3:]
00108         elif arg[:3] == "sp=":
00109             config.state['ServantPrefix']          = arg[3:]
00110         elif arg[:4] == "sns=":
00111             config.state['ServantNs']              = arg[4:].split('::')
00112         elif arg[:5] == "sdir=":
00113             config.state['ServantDir']             = arg[5:]
00114         # for adapter
00115         elif arg[:3] == "as=":
00116             config.state['AdapterSuffix']          = arg[3:]
00117         elif arg[:3] == "ap=":
00118             config.state['AdapterPrefix']          = arg[3:]
00119         elif arg[:4] == "ans=":
00120             config.state['AdapterNs']              = arg[4:].split('::')
00121         elif arg[:5] == "adir=":
00122             config.state['AdapterDir']             = arg[5:]
00123         # for proxy 
00124         elif arg[:3] == "ps=":
00125             config.state['ProxySuffix']            = arg[3:]
00126         elif arg[:3] == "pp=":
00127             config.state['ProxyPrefix']            = arg[3:]
00128         elif arg[:4] == "pns=":
00129             config.state['ProxyNs']                = arg[4:].split('::')
00130         elif arg[:5] == "pdir=":
00131             config.state['ProxyDir']               = arg[5:]
00132         # for interface
00133         elif arg[:3] == "is=":
00134             config.state['IfaceSuffix']            = arg[3:]
00135         elif arg[:3] == "ip=":
00136             config.state['IfacePrefix']            = arg[3:]
00137         elif arg[:4] == "ins=":
00138             config.state['IfaceNs']                = arg[4:].split('::')
00139         elif arg[:5] == "idir=":
00140             config.state['IfaceDir']               = arg[5:]
00141         else:
00142             util.fatalError("Argument \"" + str(arg) + "\" is unknown")
00143 
00144 run_before = 0
00145 
00146 
00147 def run(tree, args):
00148     """Entrypoint to the doil backend"""
00149 
00150     global run_before
00151 
00152     if run_before:
00153         util.fatalError("Sorry, the doil backend cannot process more "
00154                         "than one IDL file at a time.")
00155     run_before = 1
00156 
00157     dirname, filename = os.path.split(tree.file())
00158     basename,ext      = os.path.splitext(filename)
00159     config.state['Basename']  = basename
00160     config.state['Directory'] = dirname
00161     
00162     process_args(args)
00163 
00164     if config.state['MappingFile'] == '':
00165         config.state['TypeMapping'] = {}
00166     else:
00167         import yaml
00168         mapping_file = config.state['MappingFile']
00169         f = open(mapping_file, "r")
00170         mapping = yaml.load(f.read())
00171         f.close()
00172         config.state['TypeMapping'] = mapping
00173 
00174 
00175     try:
00176         # Check the input tree only contains stuff we understand
00177         support.checkIDL(tree)
00178 
00179         # initialise the handy ast module
00180         ast.__init__(tree)
00181 
00182         tree.accept(id.WalkTree())
00183         # Initialise the descriptor generating code
00184         # currently doil does not use descriptor
00185         #        descriptor.__init__(tree)
00186         from omniidl_be.doil import dictbuilder
00187         dict = dictbuilder.run(tree, config.state)
00188 
00189         if config.state['Interface']:
00190             from omniidl_be.doil import interface
00191             interface.generate_interface(dict)
00192             interface.generate_types(dict)
00193         if config.state['CORBAServant']:
00194             from omniidl_be.doil import corba
00195             corba.generate_servant(dict)
00196             corba.generate_types(dict)
00197         if config.state['CORBAAdapter']:
00198             from omniidl_be.doil import corba
00199             corba.generate_adapter(dict)
00200             corba.generate_types(dict)
00201         if config.state['CORBAProxy']:
00202             from omniidl_be.doil import corba
00203             corba.generate_proxy(dict)
00204             corba.generate_types(dict)
00205         if config.state['IceSlice']:
00206             from omniidl_be.doil import ice
00207             ice.generate_slice(dict)
00208 
00209         if config.state['IceAdapter']:
00210             from omniidl_be.doil import ice
00211             ice.generate_adapter(dict)
00212 
00213         if config.state['IceProxy']:
00214             from omniidl_be.doil import ice
00215             ice.generate_proxy(dict)
00216 
00217         if config.state['IceServant']:
00218             from omniidl_be.doil import ice
00219             ice.generate_servant(dict)
00220 
00221     except AttributeError, e:
00222         name = e[0]
00223         unsupported_visitors = map(lambda x:"visit" + x,
00224                                    AST_unsupported_nodes[:])
00225         if name in unsupported_visitors:
00226             util.unsupportedIDL()
00227             
00228         util.fatalError("An AttributeError exception was caught")
00229     except SystemExit, e:
00230         raise e
00231     except:
00232         util.fatalError("An internal exception was caught")


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:37