140 |
146 |
141 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
147 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
142 """ |
148 """ |
143 Class to represent a Python function. |
149 Class to represent a Python function. |
144 """ |
150 """ |
145 def __init__(self, module, name, file, lineno, signature='', separator=','): |
151 def __init__(self, module, name, file, lineno, signature='', separator=',', |
|
152 modifierType=ClbrBaseClasses.Function.General): |
146 """ |
153 """ |
147 Constructor |
154 Constructor |
148 |
155 |
149 @param module name of the module containing this function |
156 @param module name of the module containing this function |
150 @param name name of this function |
157 @param name name of this function |
151 @param file filename containing this class |
158 @param file filename containing this class |
152 @param lineno linenumber of the class definition |
159 @param lineno linenumber of the class definition |
153 @param signature parameterlist of the method |
160 @param signature parameterlist of the method |
154 @param separator string separating the parameters |
161 @param separator string separating the parameters |
|
162 @param modifierType type of the function |
155 """ |
163 """ |
156 ClbrBaseClasses.Function.__init__(self, module, name, file, lineno, |
164 ClbrBaseClasses.Function.__init__(self, module, name, file, lineno, |
157 signature, separator) |
165 signature, separator, modifierType) |
158 VisibilityMixin.__init__(self) |
166 VisibilityMixin.__init__(self) |
159 |
167 |
160 |
168 |
161 class Attribute(ClbrBaseClasses.Attribute, VisibilityMixin): |
169 class Attribute(ClbrBaseClasses.Attribute, VisibilityMixin): |
162 """ |
170 """ |
262 _modules[module] = dict |
270 _modules[module] = dict |
263 return dict |
271 return dict |
264 |
272 |
265 lineno, last_lineno_pos = 1, 0 |
273 lineno, last_lineno_pos = 1, 0 |
266 i = 0 |
274 i = 0 |
|
275 modifierType = ClbrBaseClasses.Function.General |
|
276 modifierIndent = -1 |
267 while True: |
277 while True: |
268 m = _getnext(src, i) |
278 m = _getnext(src, i) |
269 if not m: |
279 if not m: |
270 break |
280 break |
271 start, i = m.span() |
281 start, i = m.span() |
272 |
282 |
273 if m.start("Method") >= 0: |
283 if m.start("MethodModifier") >= 0: |
|
284 modifierIndent = _indent(m.group("MethodModifierIndent")) |
|
285 modifierType = m.group("MethodModifierType") |
|
286 elif m.start("Method") >= 0: |
274 # found a method definition or function |
287 # found a method definition or function |
275 thisindent = _indent(m.group("MethodIndent")) |
288 thisindent = _indent(m.group("MethodIndent")) |
276 meth_name = m.group("MethodName") |
289 meth_name = m.group("MethodName") |
277 meth_sig = m.group("MethodSignature") |
290 meth_sig = m.group("MethodSignature") |
278 meth_sig = meth_sig.replace('\\\n', '') |
291 meth_sig = meth_sig.replace('\\\n', '') |
279 meth_sig = _commentsub('', meth_sig) |
292 meth_sig = _commentsub('', meth_sig) |
280 lineno = lineno + src.count('\n', last_lineno_pos, start) |
293 lineno = lineno + src.count('\n', last_lineno_pos, start) |
281 last_lineno_pos = start |
294 last_lineno_pos = start |
|
295 if modifierType and modifierIndent == thisindent: |
|
296 if modifierType == "@staticmethod": |
|
297 modifier = ClbrBaseClasses.Function.Static |
|
298 elif modifierType == "@classmethod": |
|
299 modifier = ClbrBaseClasses.Function.Class |
|
300 else: |
|
301 modifier = ClbrBaseClasses.Function.General |
|
302 else: |
|
303 modifier = ClbrBaseClasses.Function.General |
282 # modify indentation level for conditional defines |
304 # modify indentation level for conditional defines |
283 if conditionalsstack: |
305 if conditionalsstack: |
284 if thisindent > conditionalsstack[-1]: |
306 if thisindent > conditionalsstack[-1]: |
285 if not deltaindentcalculated: |
307 if not deltaindentcalculated: |
286 deltastack.append(thisindent - conditionalsstack[-1]) |
308 deltastack.append(thisindent - conditionalsstack[-1]) |
302 # it's a class method |
324 # it's a class method |
303 cur_class = classstack[-1][0] |
325 cur_class = classstack[-1][0] |
304 if cur_class: |
326 if cur_class: |
305 # it's a method/nested def |
327 # it's a method/nested def |
306 f = Function(None, meth_name, |
328 f = Function(None, meth_name, |
307 file, lineno, meth_sig) |
329 file, lineno, meth_sig, modifierType=modifier) |
308 cur_class._addmethod(meth_name, f) |
330 cur_class._addmethod(meth_name, f) |
309 else: |
331 else: |
310 # it's a function |
332 # it's a function |
311 f = Function(module, meth_name, |
333 f = Function(module, meth_name, |
312 file, lineno, meth_sig) |
334 file, lineno, meth_sig, modifierType=modifier) |
313 if meth_name in dict_counts: |
335 if meth_name in dict_counts: |
314 dict_counts[meth_name] += 1 |
336 dict_counts[meth_name] += 1 |
315 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) |
337 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) |
316 else: |
338 else: |
317 dict_counts[meth_name] = 0 |
339 dict_counts[meth_name] = 0 |
318 dict[meth_name] = f |
340 dict[meth_name] = f |
319 classstack.append((f, thisindent)) # Marker for nested fns |
341 classstack.append((f, thisindent)) # Marker for nested fns |
|
342 |
|
343 # reset the modifier settings |
|
344 modifierType = ClbrBaseClasses.Function.General |
|
345 modifierIndent = -1 |
320 |
346 |
321 elif m.start("String") >= 0: |
347 elif m.start("String") >= 0: |
322 pass |
348 pass |
323 |
349 |
324 elif m.start("Class") >= 0: |
350 elif m.start("Class") >= 0: |