__init__.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- python -*-
3 #
4 # @file omniidl_be/doil/__init__.py
5 # @brief doil backend for omniidl
6 # @date $Date$
7 # @author Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # Copyright (C) 2008
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id$
17 #
18 
19 # Entrypoint to the doil backend
20 
21 # modules from omniidl
22 from omniidl import idlast, idlvisitor, idlutil
23 
24 # module from omniidl_be.cxx
25 from omniidl_be.cxx import support, ast, id
26 
27 # module from omniidl_be.doil
28 from omniidl_be.doil import util, config
29 
30 import re, sys, os.path
31 
32 cpp_args = ["-D__OMNIIDL_CXX__"]
33 usage_string = """\
34  -Wbm=<mapfile> Specify type mapping rule file (mandatory)
35  -Wbi=<include> Specify include files
36  -Wbimplicit Process included IDLs implicitly
37  -Wbinterface Generate doil C++ interface header
38  -Wbcorbaservant Generate doil servant class for CORBA
39  -Wbcorbaadapter Generate doil adapter class for CORBA
40  -Wbcorbaproxy Generate doil proxy class for CORBA
41  -Wbiceslice Generate Ice slice file from CORBA IDL
42  -Wbiceservant Generate doil servant class for Ice
43  -Wbiceadapter Generate doil adapter class for Ice
44  -Wbiceproxy Generate doil proxy class for Ice
45 
46 [ options for servant class ]
47  -Wbss=<suffix> Specify suffix for generated servant files [default Servant]
48  -Wbsp=<prefix> Specify prefix for generated servant files [default None]
49  -Wbsns=<ns> Specify namespsace of generated servant class [default None]
50  -Wbsdir=<ns> Specify directory of generated servant header [default None]
51 
52 [ options for adapter class ]
53  -Wbas=<suffix> Specify suffix for generated adapter class [default Adapter]
54  -Wbap=<prefix> Specify prefix for generated adapter class [default None]
55  -Wbans=<ns> Specify namespsace of generated adapter class [default None]
56  -Wbadir=<ns> Specify directory of generated adapter header [default None]
57 
58 [ options for proxy class ]
59  -Wbps=<suffix> Specify suffix for generated proxy class [default Proxy]
60  -Wbpp=<prefix> Specify prefix for generated proxy class [default None]
61  -Wbpns=<ns> Specify namespsace of generated proxy class [default None]
62  -Wbpdir=<ns> Specify directory of generated proxy header [default None]
63 
64 [ options for interface class ]
65  -Wbis=<suffix> Specify suffix for local interface class [default None]
66  -Wbip=<prefix> Specify prefix for local interface class [default I]
67  -Wbins=<ns> Specify namespsace of local interface class [default None]
68  -Wbidir=<ns> Specify directory of local interface class [default None]
69 
70 """
71 
72 # Encountering an unknown AST node will cause an AttributeError exception
73 # to be thrown in one of the visitors. Store a list of those not-supported
74 # so we can produce a friendly error message later.
75 AST_unsupported_nodes = [ "Native", "StateMember", "Factory", "ValueForward",
76  "ValueBox", "ValueAbs", "Value" ]
77 
78 def process_args(args):
79  for arg in args:
80  if arg == "d":
81  config.state['Debug'] = True
82  elif arg[:2] == "m=":
83  config.state['MappingFile'] = arg[2:]
84  elif arg[:2] == "i=":
85  config.state['IncludeHeaders'].append(arg[2:])
86  # generator options
87  elif arg == "implicit":
88  config.state['ImplicitInclude'] = True
89  elif arg == "interface":
90  config.state['Interface'] = True
91  elif arg == "corbaservant":
92  config.state['CORBAServant'] = True
93  elif arg == "corbaadapter":
94  config.state['CORBAAdapter'] = True
95  elif arg == "corbaproxy":
96  config.state['CORBAProxy'] = True
97  elif arg == "iceslice":
98  config.state['IceSlice'] = True
99  elif arg == "iceservant":
100  config.state['IceServant'] = True
101  elif arg == "iceadapter":
102  config.state['IceAdapter'] = True
103  elif arg == "iceproxy":
104  config.state['IceProxy'] = True
105  # for servant
106  elif arg[:3] == "ss=":
107  config.state['ServantSuffix'] = arg[3:]
108  elif arg[:3] == "sp=":
109  config.state['ServantPrefix'] = arg[3:]
110  elif arg[:4] == "sns=":
111  config.state['ServantNs'] = arg[4:].split('::')
112  elif arg[:5] == "sdir=":
113  config.state['ServantDir'] = arg[5:]
114  # for adapter
115  elif arg[:3] == "as=":
116  config.state['AdapterSuffix'] = arg[3:]
117  elif arg[:3] == "ap=":
118  config.state['AdapterPrefix'] = arg[3:]
119  elif arg[:4] == "ans=":
120  config.state['AdapterNs'] = arg[4:].split('::')
121  elif arg[:5] == "adir=":
122  config.state['AdapterDir'] = arg[5:]
123  # for proxy
124  elif arg[:3] == "ps=":
125  config.state['ProxySuffix'] = arg[3:]
126  elif arg[:3] == "pp=":
127  config.state['ProxyPrefix'] = arg[3:]
128  elif arg[:4] == "pns=":
129  config.state['ProxyNs'] = arg[4:].split('::')
130  elif arg[:5] == "pdir=":
131  config.state['ProxyDir'] = arg[5:]
132  # for interface
133  elif arg[:3] == "is=":
134  config.state['IfaceSuffix'] = arg[3:]
135  elif arg[:3] == "ip=":
136  config.state['IfacePrefix'] = arg[3:]
137  elif arg[:4] == "ins=":
138  config.state['IfaceNs'] = arg[4:].split('::')
139  elif arg[:5] == "idir=":
140  config.state['IfaceDir'] = arg[5:]
141  else:
142  util.fatalError("Argument \"" + str(arg) + "\" is unknown")
143 
144 run_before = 0
145 
146 
147 def run(tree, args):
148  """Entrypoint to the doil backend"""
149 
150  global run_before
151 
152  if run_before:
153  util.fatalError("Sorry, the doil backend cannot process more "
154  "than one IDL file at a time.")
155  run_before = 1
156 
157  dirname, filename = os.path.split(tree.file())
158  basename,ext = os.path.splitext(filename)
159  config.state['Basename'] = basename
160  config.state['Directory'] = dirname
161 
162  process_args(args)
163 
164  if config.state['MappingFile'] == '':
165  config.state['TypeMapping'] = {}
166  else:
167  import yaml
168  mapping_file = config.state['MappingFile']
169  f = open(mapping_file, "r")
170  mapping = yaml.load(f.read())
171  f.close()
172  config.state['TypeMapping'] = mapping
173 
174 
175  try:
176  # Check the input tree only contains stuff we understand
177  support.checkIDL(tree)
178 
179  # initialise the handy ast module
180  ast.__init__(tree)
181 
182  tree.accept(id.WalkTree())
183  # Initialise the descriptor generating code
184  # currently doil does not use descriptor
185  # descriptor.__init__(tree)
186  from omniidl_be.doil import dictbuilder
187  dict = dictbuilder.run(tree, config.state)
188 
189  if config.state['Interface']:
190  from omniidl_be.doil import interface
191  interface.generate_interface(dict)
192  interface.generate_types(dict)
193  if config.state['CORBAServant']:
194  from omniidl_be.doil import corba
195  corba.generate_servant(dict)
196  corba.generate_types(dict)
197  if config.state['CORBAAdapter']:
198  from omniidl_be.doil import corba
199  corba.generate_adapter(dict)
200  corba.generate_types(dict)
201  if config.state['CORBAProxy']:
202  from omniidl_be.doil import corba
203  corba.generate_proxy(dict)
204  corba.generate_types(dict)
205  if config.state['IceSlice']:
206  from omniidl_be.doil import ice
207  ice.generate_slice(dict)
208 
209  if config.state['IceAdapter']:
210  from omniidl_be.doil import ice
211  ice.generate_adapter(dict)
212 
213  if config.state['IceProxy']:
214  from omniidl_be.doil import ice
215  ice.generate_proxy(dict)
216 
217  if config.state['IceServant']:
218  from omniidl_be.doil import ice
219  ice.generate_servant(dict)
220 
221  except AttributeError, e:
222  name = e[0]
223  unsupported_visitors = map(lambda x:"visit" + x,
224  AST_unsupported_nodes[:])
225  if name in unsupported_visitors:
226  util.unsupportedIDL()
227 
228  util.fatalError("An AttributeError exception was caught")
229  except SystemExit, e:
230  raise e
231  except:
232  util.fatalError("An internal exception was caught")
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:346
def run(tree, args)
Definition: __init__.py:147
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
Definition: NVUtil.cpp:354
def process_args(args)
Definition: __init__.py:78


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:42