You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When developing with libadalang/python, I have found the following function very useful. I just pass it a node, and it dumps all useful properties on the console. I wonder whether the libadalang developers already have something similar or better that could be made more official... A small part of the complexity here is to work around a few libadalang crashes when calling some of the functions (although I have noticed less and less of these in the last few months :-)
def dump(v):
"""
Debug only
"""
import inspect
methods = set()
staticmethods = set()
fields = {}
for name in dir(v):
if name in ('p_int_type', 'p_bool_type', 'dump', 'dump_str',
'p_universal_int_type', 'p_universal_real_type',
'find', 'findall', 'finditer', 'is_a',
'p_complete', 'p_gnat_xref', 'p_as_symbol_array',
'p_referenced_decl_internal',
):
continue
if name.startswith('_'):
continue
try:
value = getattr(v, name)
except:
value = '??? Error when computing'
if inspect.ismethod(value):
methods.add(name)
elif inspect.isfunction(value):
staticmethods.add(name)
else:
fields[name] = value
print("=== Dump: %s" % v)
print(" inheritance tree: %s" %
map(lambda n: n.__name__, inspect.getmro(type(v))))
if methods:
print(" methods: %s" % sorted(methods))
if staticmethods:
print(" staticmethods: %s" % sorted(staticmethods))
for name in sorted(fields):
value = fields[name]
if name in ('p_referenced_decl', 'p_referenced_id',
'p_is_dot_call', 'p_is_static_expr', 'p_name_is',
):
try:
name = name + '()'
value = value()
except:
value = '??? Error when calling'
try:
value = str(value)
except:
value = "??? Exception when converting to string"
print(' %-18s: %s' % (name, value))
The text was updated successfully, but these errors were encountered:
That's an interesting function! To be honest, I don't need such a function because I usually explore the structure from an interactive REPL with completion, such as the playground, but I can see the benefits of seeing all the info at once. I will keep this open to see if there's something to be done inside LAL. Thanks for sharing it
When developing with libadalang/python, I have found the following function very useful. I just pass it a node, and it dumps all useful properties on the console. I wonder whether the libadalang developers already have something similar or better that could be made more official... A small part of the complexity here is to work around a few libadalang crashes when calling some of the functions (although I have noticed less and less of these in the last few months :-)
The text was updated successfully, but these errors were encountered: