Add -debug-symtabs and -debug-qsymtabs options for debugging symbol tables

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11724 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-11-04 22:49:39 +00:00
commit 64d1b6f0c6
6 changed files with 72 additions and 27 deletions

View file

@ -1,6 +1,12 @@
Version 1.3.41 (in progress)
============================
2009-11-04: wsfulton
Add new debug options:
-debug-symtabs - Display symbol tables information
-debug-qsymtabs - Display symbol tables summary information using fully
qualified names
2009-11-03: wsfulton
Fix some usage of global scope operator, for example:

View file

@ -3598,6 +3598,8 @@ There are various command line options which can aid debugging a SWIG interface
<div class="shell"><pre>
-debug-classes - Display information about the classes found in the interface
-debug-module &lt;n&gt; - Display module parse tree at stages 1-4, &lt;n&gt; is a csv list of stages
-debug-symtabs - Display symbol tables information
-debug-qsymtabs - Display symbol tables summary information using fully qualified names
-debug-tags - Display information about the tags found in the interface
-debug-template - Display information for debugging templates
-debug-top &lt;n&gt; - Display entire parse tree at stages 1-4, &lt;n&gt; is a csv list of stages

View file

@ -817,14 +817,8 @@ static List *make_inherit_list(String *clsname, List *names) {
/* If the class name is qualified. We need to create or lookup namespace entries */
static Symtab *get_global_scope() {
Symtab *symtab = Swig_symbol_current();
Node *pn = parentNode(symtab);
while (pn) {
symtab = pn;
pn = parentNode(symtab);
if (!pn) break;
}
static Symtab *set_scope_to_global() {
Symtab *symtab = Swig_symbol_global_scope();
Swig_symbol_setscope(symtab);
return symtab;
}
@ -869,11 +863,11 @@ static String *resolve_node_scope(String *cname) {
String *nprefix = NewString(Char(prefix)+2);
Delete(prefix);
prefix= nprefix;
gscope = get_global_scope();
gscope = set_scope_to_global();
}
if (!prefix || (Len(prefix) == 0)) {
/* Use the global scope, but we need to add a 'global' namespace. */
if (!gscope) gscope = get_global_scope();
if (!gscope) gscope = set_scope_to_global();
/* note that this namespace is not the "unnamed" one,
and we don't use Setattr(nscope,"name", ""),
because the unnamed namespace is private */

View file

@ -62,6 +62,8 @@ static const char *usage1 = (const char *) "\
-copyright - Display copyright notices\n\
-debug-classes - Display information about the classes found in the interface\n\
-debug-module <n>- Display module parse tree at stages 1-4, <n> is a csv list of stages\n\
-debug-symtabs - Display symbol tables information\n\
-debug-qsymtabs - Display symbol tables summary information using fully qualified names\n\
-debug-tags - Display information about the tags found in the interface\n\
-debug-template - Display information for debugging templates\n\
-debug-top <n> - Display entire parse tree at stages 1-4, <n> is a csv list of stages\n\
@ -162,6 +164,8 @@ static int no_cpp = 0;
static char *outfile_name = 0;
static char *outfile_name_h = 0;
static int tm_debug = 0;
static int dump_symtabs = 0;
static int dump_qsymtabs = 0;
static int dump_tags = 0;
static int dump_module = 0;
static int dump_top = 0;
@ -716,6 +720,12 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strncmp(argv[i], "-w", 2) == 0) {
Swig_mark_arg(i);
Swig_warnfilter(argv[i] + 2, 1);
} else if (strcmp(argv[i], "-debug-symtabs") == 0) {
dump_symtabs = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-debug-qsymtabs") == 0) {
dump_qsymtabs = 1;
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-debug-tags") == 0) || (strcmp(argv[i], "-dump_tags") == 0)) {
dump_tags = 1;
Swig_mark_arg(i);
@ -1145,6 +1155,14 @@ int SWIG_main(int argc, char *argv[], Language *l) {
SwigType_print_scope(0);
}
if (dump_symtabs) {
Swig_symbol_tables_print(Swig_symbol_global_scope());
}
if (dump_qsymtabs) {
Swig_symbol_tables_summary_print();
}
if (dump_tags) {
Swig_print_tags(top, 0);
}

View file

@ -200,6 +200,8 @@ extern "C" {
/* --- Symbol table module --- */
extern void Swig_symbol_tables_print(Symtab *symtab);
extern void Swig_symbol_tables_summary_print(void);
extern void Swig_symbol_init(void);
extern void Swig_symbol_setscopename(const_String_or_char_ptr name);
extern String *Swig_symbol_getscopename(void);
@ -207,6 +209,7 @@ extern "C" {
extern Symtab *Swig_symbol_newscope(void);
extern Symtab *Swig_symbol_setscope(Symtab *);
extern Symtab *Swig_symbol_getscope(const_String_or_char_ptr symname);
extern Symtab *Swig_symbol_global_scope(void);
extern Symtab *Swig_symbol_current(void);
extern Symtab *Swig_symbol_popscope(void);
extern Node *Swig_symbol_add(const_String_or_char_ptr symname, Node *node);

View file

@ -175,20 +175,32 @@ static Hash *global_scope = 0; /* Global scope */
/* common attribute keys, to avoid calling find_key all the times */
/* -----------------------------------------------------------------------------
* Swig_symbol_tables_print()
*
* Debug display of symbol tables
* ----------------------------------------------------------------------------- */
#if 0
void Swig_symbol_dump_symtable() {
Printf(stdout, "DUMPING SYMTABLE start =======================================\n");
{
Hash *cst = Getattr(current_symtab, "csymtab");
Swig_print_tree(cst);
/*
Swig_print_tree(Getattr(cst, "NumSpace"));
*/
}
Printf(stdout, "DUMPING SYMTABLE end =======================================\n");
void Swig_symbol_tables_print(Symtab *symtab) {
if (!symtab)
symtab = current_symtab;
Printf(stdout, "SYMBOL TABLES start =======================================\n");
Swig_print_tree(symtab);
Printf(stdout, "SYMBOL TABLES finish =======================================\n");
}
/* -----------------------------------------------------------------------------
* Swig_symbol_tables_summary_print()
*
* Debug summary display of all symbol tables by fully-qualified name
* ----------------------------------------------------------------------------- */
void Swig_symbol_tables_summary_print(void) {
Printf(stdout, "SYMBOL TABLES SUMMARY start =======================================\n");
Swig_print_node(symtabs);
Printf(stdout, "SYMBOL TABLES SUMMARY finish =======================================\n");
}
#endif
/* -----------------------------------------------------------------------------
* Swig_symbol_init()
@ -196,7 +208,7 @@ void Swig_symbol_dump_symtable() {
* Create a new symbol table object
* ----------------------------------------------------------------------------- */
void Swig_symbol_init() {
void Swig_symbol_init(void) {
current = NewHash();
current_symtab = NewHash();
@ -240,7 +252,7 @@ void Swig_symbol_setscopename(const_String_or_char_ptr name) {
* Get the C scopename of the current symbol table
* ----------------------------------------------------------------------------- */
String *Swig_symbol_getscopename() {
String *Swig_symbol_getscopename(void) {
return Getattr(current_symtab, "name");
}
@ -295,7 +307,7 @@ String *Swig_symbol_qualifiedscopename(Symtab *symtab) {
* Create a new scope. Returns the newly created scope.
* ----------------------------------------------------------------------------- */
Symtab *Swig_symbol_newscope() {
Symtab *Swig_symbol_newscope(void) {
Hash *n;
Hash *hsyms, *h;
@ -346,7 +358,7 @@ Symtab *Swig_symbol_setscope(Symtab *sym) {
* scope to the parent scope.
* ----------------------------------------------------------------------------- */
Symtab *Swig_symbol_popscope() {
Symtab *Swig_symbol_popscope(void) {
Hash *h = current_symtab;
current_symtab = Getattr(current_symtab, "parentNode");
assert(current_symtab);
@ -357,13 +369,23 @@ Symtab *Swig_symbol_popscope() {
return h;
}
/* -----------------------------------------------------------------------------
* Swig_symbol_global_scope()
*
* Return the symbol table for the global scope.
* ----------------------------------------------------------------------------- */
Symtab *Swig_symbol_global_scope(void) {
return global_scope;
}
/* -----------------------------------------------------------------------------
* Swig_symbol_current()
*
* Return the current symbol table.
* ----------------------------------------------------------------------------- */
Symtab *Swig_symbol_current() {
Symtab *Swig_symbol_current(void) {
return current_symtab;
}