From e7789a63b1c78cee4517ad76df9c702fddbc34ed Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Sun, 15 Nov 2020 21:17:32 -0500 Subject: [PATCH 1/2] Defer inspect.currentframe only used for debugging --- CppHeaderParser/CppHeaderParser.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CppHeaderParser/CppHeaderParser.py b/CppHeaderParser/CppHeaderParser.py index af29b45..6e1c487 100644 --- a/CppHeaderParser/CppHeaderParser.py +++ b/CppHeaderParser/CppHeaderParser.py @@ -100,6 +100,12 @@ def warning_print(fmt, *args): if debug: + class _debug_caller_lineno: + def __str__(self): + return str(inspect.currentframe().f_back.f_back.f_back.f_lineno) + + debug_caller_lineno = _debug_caller_lineno() + def debug_print(fmt, *args): fmt = "[%4d] " + fmt args = (inspect.currentframe().f_back.f_lineno,) + args @@ -108,6 +114,8 @@ def debug_print(fmt, *args): else: + debug_caller_lineno = None + def debug_print(fmt, *args): pass @@ -3237,10 +3245,10 @@ def _evaluate_stack(self, token=None): nameStackCopy = self.nameStack[:] debug_print( - "Evaluating stack %s\n BraceDepth: %s (called from %d)", + "Evaluating stack %s\n BraceDepth: %s (called from %s)", self.nameStack, self.braceDepth, - inspect.currentframe().f_back.f_lineno, + debug_caller_lineno, ) # Handle special case of overloading operator () From b60b0f2073f57d6301948a315581123b9d6accba Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Sun, 15 Nov 2020 21:24:11 -0500 Subject: [PATCH 2/2] Defer formatting for various debug messages --- CppHeaderParser/CppHeaderParser.py | 39 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/CppHeaderParser/CppHeaderParser.py b/CppHeaderParser/CppHeaderParser.py index 6e1c487..2825efb 100644 --- a/CppHeaderParser/CppHeaderParser.py +++ b/CppHeaderParser/CppHeaderParser.py @@ -123,9 +123,9 @@ def debug_print(fmt, *args): if debug_trace: def trace_print(*args): - sys.stdout.write("[%s] " % (inspect.currentframe().f_back.f_lineno)) + sys.stdout.write("[%s]" % (inspect.currentframe().f_back.f_lineno)) for a in args: - sys.stdout.write("%s " % a) + sys.stdout.write(" %s" % a) sys.stdout.write("\n") @@ -729,7 +729,7 @@ def __init__(self, nameStack, curTemplate, doxygen, location, defaultAccess): if curTemplate: self["template"] = curTemplate - trace_print("Setting template to '%s'" % self["template"]) + trace_print("Setting template to", self["template"]) methodAccessSpecificList = {} propertyAccessSpecificList = {} @@ -1865,7 +1865,6 @@ def finalize_vars(self): else: trace_print("WARN-this should almost never happen!") trace_print(var) - trace_print("-" * 80) var["unresolved"] = True elif tag in self._template_typenames: @@ -1950,23 +1949,23 @@ def finalize_vars(self): # var['raw_type'] = var['raw_type'][2:] # Take care of #defines and #pragmas etc - trace_print("Processing precomp_macro_buf: %s" % self._precomp_macro_buf) + trace_print("Processing precomp_macro_buf:", self._precomp_macro_buf) for m, location in self._precomp_macro_buf: macro = m.replace("\\n", "\n") ml = macro.lower() try: if ml.startswith("#define"): - trace_print("Adding #define %s" % macro) + trace_print("Adding #define", macro) define = CppDefine(macro, location) self.defines.append(define["value"]) self.defines_detail.append(define) elif ml.startswith("#pragma"): - trace_print("Adding #pragma %s" % macro) + trace_print("Adding #pragma", macro) pragma = CppPragma(macro, location) self.pragmas_detail.append(pragma) self.pragmas.append(pragma["value"]) elif ml.startswith("#include"): - trace_print("Adding #include %s" % macro) + trace_print("Adding #include", macro) include = CppInclude(macro, location) self.includes.append(include["value"]) self.includes_detail.append(include) @@ -2455,8 +2454,9 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None): # Is it really a list of variables? if leftMostComma != 0: trace_print( - "Multiple variables for namestack in %s. Separating processing" - % self.nameStack + "Multiple variables for namestack in", + self.nameStack, + ". Separating processing", ) orig_nameStack = self.nameStack[:] @@ -2580,7 +2580,6 @@ def _evaluate_class_stack(self): if key in self.classes: trace_print("ERROR name collision:", key) self.classes[key].show() - trace_print("-" * 80) newClass.show() assert key not in self.classes # namespace collision self.classes[key] = newClass @@ -3290,7 +3289,7 @@ def _evaluate_stack(self, token=None): ) ): debug_print("trace") - trace_print("typedef %s", self.stack) + trace_print("typedef", self.stack) self._evaluate_typedef() return @@ -3407,7 +3406,7 @@ def _evaluate_stack(self, token=None): elif self.braceDepth > len(self.nameSpaces) + 1: debug_print("trace") else: - debug_print("Discarded statement %s" % (self.nameStack,)) + debug_print("Discarded statement %s", self.nameStack) try: self.nameStackHistory[self.braceDepth] = (nameStackCopy, self.curClass) @@ -3643,17 +3642,17 @@ def _strip_parent_keys(self): obj_queue = [self] while len(obj_queue): obj = obj_queue.pop() - trace_print("pop %s type %s" % (obj, type(obj))) + trace_print("pop", obj, "type", type(obj)) try: if "parent" in obj.keys(): del obj["parent"] - trace_print("Stripped parent from %s" % obj.keys()) + trace_print("Stripped parent from", obj.keys()) except: pass try: if "method" in obj.keys(): del obj["method"] - trace_print("Stripped method from %s" % obj.keys()) + trace_print("Stripped method from", obj.keys()) except: pass # Figure out what sub types are one of ours @@ -3661,17 +3660,17 @@ def _strip_parent_keys(self): if not hasattr(obj, "keys"): obj = obj.__dict__ for k in obj.keys(): - trace_print("-Try key %s" % (k)) - trace_print("-type %s" % (type(obj[k]))) + trace_print("-Try key", k) + trace_print("-type", type(obj[k])) if k in ["nameStackHistory", "parent", "_public_typedefs"]: continue if type(obj[k]) == list: for i in obj[k]: - trace_print("push l %s" % i) + trace_print("push l", i) obj_queue.append(i) elif type(obj[k]) == dict: if len(obj): - trace_print("push d %s" % obj[k]) + trace_print("push d", obj[k]) obj_queue.append(obj[k]) elif type(obj[k]) == type(type(0)): if type(obj[k]) == int: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy