154 |
154 |
155 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub |
155 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub |
156 |
156 |
157 _modules = {} # cache of modules we've seen |
157 _modules = {} # cache of modules we've seen |
158 |
158 |
|
159 |
159 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase): |
160 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase): |
160 """ |
161 """ |
161 Mixin class implementing the notion of visibility. |
162 Mixin class implementing the notion of visibility. |
162 """ |
163 """ |
163 def __init__(self): |
164 def __init__(self): |
164 """ |
165 """ |
165 Method to initialize the visibility. |
166 Method to initialize the visibility. |
166 """ |
167 """ |
167 self.setPublic() |
168 self.setPublic() |
|
169 |
168 |
170 |
169 class Class(ClbrBaseClasses.Class, VisibilityMixin): |
171 class Class(ClbrBaseClasses.Class, VisibilityMixin): |
170 """ |
172 """ |
171 Class to represent a Ruby class. |
173 Class to represent a Ruby class. |
172 """ |
174 """ |
181 @param lineno linenumber of the class definition |
183 @param lineno linenumber of the class definition |
182 """ |
184 """ |
183 ClbrBaseClasses.Class.__init__(self, module, name, super, file, lineno) |
185 ClbrBaseClasses.Class.__init__(self, module, name, super, file, lineno) |
184 VisibilityMixin.__init__(self) |
186 VisibilityMixin.__init__(self) |
185 |
187 |
|
188 |
186 class Module(ClbrBaseClasses.Module, VisibilityMixin): |
189 class Module(ClbrBaseClasses.Module, VisibilityMixin): |
187 """ |
190 """ |
188 Class to represent a Ruby module. |
191 Class to represent a Ruby module. |
189 """ |
192 """ |
190 def __init__(self, module, name, file, lineno): |
193 def __init__(self, module, name, file, lineno): |
197 @param lineno linenumber of the class definition |
200 @param lineno linenumber of the class definition |
198 """ |
201 """ |
199 ClbrBaseClasses.Module.__init__(self, module, name, file, lineno) |
202 ClbrBaseClasses.Module.__init__(self, module, name, file, lineno) |
200 VisibilityMixin.__init__(self) |
203 VisibilityMixin.__init__(self) |
201 |
204 |
|
205 |
202 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
206 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
203 """ |
207 """ |
204 Class to represent a Ruby function. |
208 Class to represent a Ruby function. |
205 """ |
209 """ |
206 def __init__(self, module, name, file, lineno, signature = '', separator = ','): |
210 def __init__(self, module, name, file, lineno, signature='', separator=','): |
207 """ |
211 """ |
208 Constructor |
212 Constructor |
209 |
213 |
210 @param module name of the module containing this function |
214 @param module name of the module containing this function |
211 @param name name of this function |
215 @param name name of this function |
212 @param file filename containing this class |
216 @param file filename containing this class |
213 @param lineno linenumber of the class definition |
217 @param lineno linenumber of the class definition |
214 @param signature parameterlist of the method |
218 @param signature parameterlist of the method |
215 @param separator string separating the parameters |
219 @param separator string separating the parameters |
216 """ |
220 """ |
217 ClbrBaseClasses.Function.__init__(self, module, name, file, lineno, |
221 ClbrBaseClasses.Function.__init__(self, module, name, file, lineno, |
218 signature, separator) |
222 signature, separator) |
219 VisibilityMixin.__init__(self) |
223 VisibilityMixin.__init__(self) |
|
224 |
220 |
225 |
221 class Attribute(ClbrBaseClasses.Attribute, VisibilityMixin): |
226 class Attribute(ClbrBaseClasses.Attribute, VisibilityMixin): |
222 """ |
227 """ |
223 Class to represent a class or module attribute. |
228 Class to represent a class or module attribute. |
224 """ |
229 """ |
232 @param lineno linenumber of the class definition |
237 @param lineno linenumber of the class definition |
233 """ |
238 """ |
234 ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno) |
239 ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno) |
235 VisibilityMixin.__init__(self) |
240 VisibilityMixin.__init__(self) |
236 self.setPrivate() |
241 self.setPrivate() |
|
242 |
237 |
243 |
238 def readmodule_ex(module, path=[]): |
244 def readmodule_ex(module, path=[]): |
239 ''' |
245 ''' |
240 Read a Ruby file and return a dictionary of classes, functions and modules. |
246 Read a Ruby file and return a dictionary of classes, functions and modules. |
241 |
247 |
262 # not Ruby source, can't do anything with this module |
268 # not Ruby source, can't do anything with this module |
263 _modules[module] = dict |
269 _modules[module] = dict |
264 return dict |
270 return dict |
265 |
271 |
266 _modules[module] = dict |
272 _modules[module] = dict |
267 classstack = [] # stack of (class, indent) pairs |
273 classstack = [] # stack of (class, indent) pairs |
268 acstack = [] # stack of (access control, indent) pairs |
274 acstack = [] # stack of (access control, indent) pairs |
269 indent = 0 |
275 indent = 0 |
270 try: |
276 try: |
271 src = Utilities.readEncodedFile(file)[0] |
277 src = Utilities.readEncodedFile(file)[0] |
272 except (UnicodeError, IOError): |
278 except (UnicodeError, IOError): |
333 dict_counts[meth_name] += 1 |
339 dict_counts[meth_name] += 1 |
334 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) |
340 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) |
335 else: |
341 else: |
336 dict_counts[meth_name] = 0 |
342 dict_counts[meth_name] = 0 |
337 dict[meth_name] = f |
343 dict[meth_name] = f |
338 classstack.append((f, thisindent)) # Marker for nested fns |
344 classstack.append((f, thisindent)) # Marker for nested fns |
339 |
345 |
340 elif m.start("String") >= 0: |
346 elif m.start("String") >= 0: |
341 pass |
347 pass |
342 |
348 |
343 elif m.start("Comment") >= 0: |
349 elif m.start("Comment") >= 0: |
479 if m.group("AttrType") is None: |
485 if m.group("AttrType") is None: |
480 nv = m.group("AttrList").split(",") |
486 nv = m.group("AttrList").split(",") |
481 if not nv: |
487 if not nv: |
482 break |
488 break |
483 name = nv[0].strip()[1:] # get rid of leading ':' |
489 name = nv[0].strip()[1:] # get rid of leading ':' |
484 attr = parent._getattribute("@"+name) or \ |
490 attr = parent._getattribute("@" + name) or \ |
485 parent._getattribute("@@"+name) or \ |
491 parent._getattribute("@@" + name) or \ |
486 Attribute(module, "@"+name, file, lineno) |
492 Attribute(module, "@" + name, file, lineno) |
487 if len(nv) == 1 or nv[1].strip() == "false": |
493 if len(nv) == 1 or nv[1].strip() == "false": |
488 attr.setProtected() |
494 attr.setProtected() |
489 elif nv[1].strip() == "true": |
495 elif nv[1].strip() == "true": |
490 attr.setPublic() |
496 attr.setPublic() |
491 parent._addattribute(attr) |
497 parent._addattribute(attr) |
492 else: |
498 else: |
493 access = m.group("AttrType") |
499 access = m.group("AttrType") |
494 for name in m.group("AttrList").split(","): |
500 for name in m.group("AttrList").split(","): |
495 name = name.strip()[1:] # get rid of leading ':' |
501 name = name.strip()[1:] # get rid of leading ':' |
496 attr = parent._getattribute("@"+name) or \ |
502 attr = parent._getattribute("@" + name) or \ |
497 parent._getattribute("@@"+name) or \ |
503 parent._getattribute("@@" + name) or \ |
498 Attribute(module, "@"+name, file, lineno) |
504 Attribute(module, "@" + name, file, lineno) |
499 if access == "_accessor": |
505 if access == "_accessor": |
500 attr.setPublic() |
506 attr.setPublic() |
501 elif access == "_reader" or access == "_writer": |
507 elif access == "_reader" or access == "_writer": |
502 if attr.isPrivate(): |
508 if attr.isPrivate(): |
503 attr.setProtected() |
509 attr.setProtected() |