diff options
Diffstat (limited to 'Source/Swig/tree.c')
-rw-r--r-- | Source/Swig/tree.c | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index e2162b7f1..438e8b73d 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -4,7 +4,7 @@ * terms also apply to certain portions of SWIG. The full details of the SWIG * license and copyrights can be found in the LICENSE and COPYRIGHT files * included with the SWIG source code as distributed by the SWIG developers - * and at http://www.swig.org/legal.html. + * and at https://www.swig.org/legal.html. * * tree.c * @@ -16,6 +16,20 @@ #include <stdarg.h> #include <assert.h> +static int debug_quiet = 0; + +/* ----------------------------------------------------------------------------- + * Swig_print_quiet() + * + * Set quiet mode when printing a parse tree node + * ----------------------------------------------------------------------------- */ + +int Swig_print_quiet(int quiet) { + int previous_quiet = debug_quiet; + debug_quiet = quiet; + return previous_quiet; +} + /* ----------------------------------------------------------------------------- * Swig_print_tags() * @@ -66,33 +80,42 @@ static void print_indent(int l) { void Swig_print_node(Node *obj) { Iterator ki; Node *cobj; + List *keys = Keys(obj); print_indent(0); - Printf(stdout, "+++ %s - %p ----------------------------------------\n", nodeType(obj), obj); - ki = First(obj); - while (ki.key) { - String *k = ki.key; - if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) || - (Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) { + if (debug_quiet) + Printf(stdout, "+++ %s ----------------------------------------\n", nodeType(obj)); + else + Printf(stdout, "+++ %s - %p ----------------------------------------\n", nodeType(obj), obj); + + SortList(keys, 0); + ki = First(keys); + while (ki.item) { + String *k = ki.item; + DOH *value = Getattr(obj, k); + if (Equal(k, "nodeType") || (*(Char(k)) == '$')) { + /* Do nothing */ + } else if (debug_quiet && (Equal(k, "firstChild") || Equal(k, "lastChild") || Equal(k, "parentNode") || Equal(k, "nextSibling") || + Equal(k, "previousSibling") || Equal(k, "symtab") || Equal(k, "csymtab") || Equal(k, "sym:symtab") || Equal(k, "sym:nextSibling") || + Equal(k, "sym:previousSibling") || Equal(k, "csym:nextSibling") || Equal(k, "csym:previousSibling"))) { /* Do nothing */ - } else if (Cmp(k, "kwargs") == 0 || Cmp(k, "parms") == 0 || Cmp(k, "wrap:parms") == 0 || - Cmp(k, "pattern") == 0 || Cmp(k, "templateparms") == 0 || Cmp(k, "throws") == 0) { + } else if (Equal(k, "kwargs") || Equal(k, "parms") || Equal(k, "wrap:parms") || Equal(k, "pattern") || Equal(k, "templateparms") || Equal(k, "throws")) { print_indent(2); /* Differentiate parameter lists by displaying within single quotes */ - Printf(stdout, "%-12s - \'%s\'\n", k, ParmList_str_defaultargs(Getattr(obj, k))); + Printf(stdout, "%-12s - \'%s\'\n", k, ParmList_str_defaultargs(value)); } else { DOH *o; const char *trunc = ""; print_indent(2); - if (DohIsString(Getattr(obj, k))) { - o = Str(Getattr(obj, k)); + if (DohIsString(value)) { + o = Str(value); if (Len(o) > 80) { trunc = "..."; } Printf(stdout, "%-12s - \"%(escape)-0.80s%s\"\n", k, o, trunc); Delete(o); } else { - Printf(stdout, "%-12s - %p\n", k, Getattr(obj, k)); + Printf(stdout, "%-12s - %p\n", k, value); } } ki = Next(ki); @@ -107,6 +130,7 @@ void Swig_print_node(Node *obj) { print_indent(1); Printf(stdout, "\n"); } + Delete(keys); } /* ----------------------------------------------------------------------------- @@ -261,12 +285,16 @@ int checkAttribute(Node *n, const_String_or_char_ptr name, const_String_or_char_ * ns - namespace for the view name for saving any attributes under * n - node * ... - list of attribute names of type char* - * This method checks that the attribute names exist in the node n and asserts if - * not. Assert will only occur unless the attribute is optional. An attribute is - * optional if it is prefixed by ?, eg "?value". If the attribute name is prefixed - * by * or ?, eg "*value" then a copy of the attribute is saved. The saved - * attributes will be restored on a subsequent call to Swig_restore(). All the - * saved attributes are saved in the view namespace (prefixed by ns). + * + * An attribute is optional if it is prefixed by ?, eg "?value". All + * non-optional attributes are checked for on node n and if any do not exist + * SWIG exits with a fatal error. + * + * If the attribute name is prefixed by * or ?, eg "*value" then a copy of the + * attribute is saved. The saved attributes will be restored on a subsequent + * call to Swig_restore(). All the saved attributes are saved in the view + * namespace (prefixed by ns). + * * This function can be called more than once with different namespaces. * ----------------------------------------------------------------------------- */ @@ -291,7 +319,7 @@ void Swig_require(const char *ns, Node *n, ...) { obj = Getattr(n, name); if (!opt && !obj) { Swig_error(Getfile(n), Getline(n), "Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", name, nodeType(n)); - assert(obj); + Exit(EXIT_FAILURE); } if (!obj) obj = DohNone; |