2 |
2 |
3 # Copyright (c) 2005 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2005 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Parse a CORBA IDL file and retrieve modules, interfaces, methods and attributes. |
7 Parse a CORBA IDL file and retrieve modules, interfaces, methods and |
8 |
8 attributes. |
9 Parse enough of a CORBA IDL file to recognize module, interface and method definitions |
9 |
10 and to find out the superclasses of an interface as well as its attributes. |
10 Parse enough of a CORBA IDL file to recognize module, interface and method |
|
11 definitions and to find out the superclasses of an interface as well as its |
|
12 attributes. |
11 |
13 |
12 It is based on the Python class browser found in this package. |
14 It is based on the Python class browser found in this package. |
13 """ |
15 """ |
14 |
16 |
15 from __future__ import unicode_literals # __IGNORE_WARNING__ |
17 from __future__ import unicode_literals # __IGNORE_WARNING__ |
140 |
142 |
141 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
143 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
142 """ |
144 """ |
143 Class to represent a CORBA IDL function. |
145 Class to represent a CORBA IDL function. |
144 """ |
146 """ |
145 def __init__(self, module, name, file, lineno, signature='', separator=','): |
147 def __init__(self, module, name, file, lineno, signature='', |
|
148 separator=','): |
146 """ |
149 """ |
147 Constructor |
150 Constructor |
148 |
151 |
149 @param module name of the module containing this function |
152 @param module name of the module containing this function |
150 @param name name of this function |
153 @param name name of this function |
174 ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno) |
177 ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno) |
175 VisibilityMixin.__init__(self) |
178 VisibilityMixin.__init__(self) |
176 |
179 |
177 |
180 |
178 def readmodule_ex(module, path=[]): |
181 def readmodule_ex(module, path=[]): |
179 ''' |
182 """ |
180 Read a CORBA IDL file and return a dictionary of classes, functions and modules. |
183 Read a CORBA IDL file and return a dictionary of classes, functions and |
|
184 modules. |
181 |
185 |
182 @param module name of the CORBA IDL file (string) |
186 @param module name of the CORBA IDL file (string) |
183 @param path path the file should be searched in (list of strings) |
187 @param path path the file should be searched in (list of strings) |
184 @return the resulting dictionary |
188 @return the resulting dictionary |
185 ''' |
189 """ |
186 global _modules |
190 global _modules |
187 |
191 |
188 dict = {} |
192 dict = {} |
189 dict_counts = {} |
193 dict_counts = {} |
190 |
194 |
241 classstack[-1][0].setEndLine(lineno - 1) |
245 classstack[-1][0].setEndLine(lineno - 1) |
242 del classstack[-1] |
246 del classstack[-1] |
243 if classstack: |
247 if classstack: |
244 # it's an interface/module method |
248 # it's an interface/module method |
245 cur_class = classstack[-1][0] |
249 cur_class = classstack[-1][0] |
246 if isinstance(cur_class, Interface) or isinstance(cur_class, Module): |
250 if isinstance(cur_class, Interface) or \ |
|
251 isinstance(cur_class, Module): |
247 # it's a method |
252 # it's a method |
248 f = Function(None, meth_name, |
253 f = Function(None, meth_name, |
249 file, lineno, meth_sig) |
254 file, lineno, meth_sig) |
250 cur_class._addmethod(meth_name, f) |
255 cur_class._addmethod(meth_name, f) |
251 # else it's a nested def |
256 # else it's a nested def |
255 # it's a function |
260 # it's a function |
256 f = Function(module, meth_name, |
261 f = Function(module, meth_name, |
257 file, lineno, meth_sig) |
262 file, lineno, meth_sig) |
258 if meth_name in dict_counts: |
263 if meth_name in dict_counts: |
259 dict_counts[meth_name] += 1 |
264 dict_counts[meth_name] += 1 |
260 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) |
265 meth_name = "{0}_{1:d}".format( |
|
266 meth_name, dict_counts[meth_name]) |
261 else: |
267 else: |
262 dict_counts[meth_name] = 0 |
268 dict_counts[meth_name] = 0 |
263 dict[meth_name] = f |
269 dict[meth_name] = f |
264 if not classstack: |
270 if not classstack: |
265 if lastGlobalEntry: |
271 if lastGlobalEntry: |