("DefFree", 2<<4), # name used but not defined in nested block
("DefFreeClass", 2<<5),# free variable from class's method
("DefImport", 2<<6), # assignment occurred via import
)
#opt flags flags to names (from symtable.h)
OPT_FLAGS= (
("optImportStar", 1),
("optTopLevel", 2),
)
BLOCK_TYPES= {
"function": "FunctionBlock",
"class": "ClassBlock",
"module": "ModuleBlock",
}
defdump_flags(flag_bits, flags_dict):
"""Dump the bits in flag_bits using the flags_dict"""
flags= []
forname, maskinflags_dict:
if (flag_bits&mask) !=0:
flags.append(name)
ifnotflags:
flags= ["0"]
return"|".join(flags)
defdump_symtable(st):
"""Dump the symtable"""
out="&SymTable{\n"
out+='Type:%s,\n'%BLOCK_TYPES[st.get_type()] # Return the type of the symbol table. Possible values are 'class', 'module', and 'function'.
out+='Name:"%s",\n'%st.get_name() # Return the table’s name. This is the name of the class if the table is for a class, the name of the function if the table is for a function, or 'top' if the table is global (get_type() returns 'module').
out+='Lineno:%s,\n'%st.get_lineno() # Return the number of the first line in the block this table represents.
out+='Unoptimized:%s,\n'%dump_flags(st._table.optimized, OPT_FLAGS) # Return False if the locals in this table can be optimized.
out+='Nested:%s,\n'%dump_bool(st.is_nested()) # Return True if the block is a nested class or function.
ifuse_readsymtab:
# Use readsymtab modules to read the bitfields which aren't normally exported