From e4eaab9e84bc76b496e1cdb353a7b8f41cc0ea76 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Thu, 2 Nov 2017 16:34:35 +0100 Subject: [PATCH] Move the print_node() subtree dump debug function to lslcommon. --- lslopt/lslcommon.py | 23 +++++++++++++++++++++++ lslopt/lslfoldconst.py | 25 ------------------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/lslopt/lslcommon.py b/lslopt/lslcommon.py index ccb2942..64d351d 100644 --- a/lslopt/lslcommon.py +++ b/lslopt/lslcommon.py @@ -70,3 +70,26 @@ LSLType2Python = {'integer':int, 'float':float, def warning(txt): assert type(txt) == unicode sys.stderr.write(u"WARNING: " + txt + u"\n") + +# Debug function +def print_node(node, indent = 0): + nt = node['nt'] + write = sys.stdout.write + spaces = ' ' * (indent*4+2) + write('%s{ nt:%s\n' % (' '*(indent*4), nt)) + if 't' in node: + write('%s,t:%s\n' % (spaces, node['t'])) + if 'name' in node: + write('%s,name:%s\n' % (spaces, node['name'])) + if 'value' in node: + write('%s,value:%s\n' % (spaces, repr(node['value']))) + + for prop in node: + if prop not in ('ch', 'nt', 't', 'name', 'value','X','SEF'): + write('%s,%s:%s\n' % (spaces, prop, repr(node[prop]))) + if 'ch' in node: + write(spaces + ',ch:[\n') + for subnode in node['ch']: + print_node(subnode, indent+1) + write(spaces + ']\n') + write(' '*(indent*4) + '}\n\n') diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 7c55197..7861908 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -25,31 +25,6 @@ import math from lslfuncopt import OptimizeFunc, OptimizeArgs, FuncOptSetup -# Debug -import sys -def print_node(node, indent): - nt = node['nt'] - write = sys.stdout.write - spaces = ' ' * (indent*4+2) - write('%s{ nt:%s\n' % (' '*(indent*4), nt)) - if 't' in node: - write('%s,t:%s\n' % (spaces, node['t'])) - if 'name' in node: - write('%s,name:%s\n' % (spaces, node['name'])) - if 'value' in node: - write('%s,value:%s\n' % (spaces, repr(node['value']))) - - for prop in node: - if prop not in ('ch', 'nt', 't', 'name', 'value','X','SEF'): - write('%s,%s:%s\n' % (spaces, prop, repr(node[prop]))) - if 'ch' in node: - write(spaces + ',ch:[\n') - for subnode in node['ch']: - print_node(subnode, indent+1) - write(spaces + ']\n') - write(' '*(indent*4) + '}\n\n') - - class foldconst(object): def isLocalVar(self, node):