sepolgen: optionally generate debugging information during parsing
PATCH 1/1 sepolgen: optionally generate debugging information during parsing
This patch allows a caller to request the output of debugging information from the parser. This is mainly useful for development / debugging of the parser.
Signed-off-by Karl MacMillan <[email protected]>
sepolgen/src/sepolgen/refparser.py +11 -9
@@ -611,11 +611,11 @@ def prep_spt(spt): parser = None lexer = None -def create_globals(module, support): +def create_globals(module, support, debug): global parser, lexer, m, spt if not parser: lexer = lex.lex() - parser = yacc.yacc(method="LALR", debug=0, write_tables=0) + parser = yacc.yacc(method="LALR", debug=debug, write_tables=0) if module is not None: m = module
@@ -627,13 +627,13 @@ def create_globals(module, support): else: spt = support -def parse(text, module=None, support=None): - create_globals(module, support) +def parse(text, module=None, support=None, debug=False): + create_globals(module, support, debug) lexer.lexdata = [] lexer.lexpos = 0 try: - parser.parse(text, debug=0) + parser.parse(text, debug=debug) except Exception, e: global error error = "internal parser error: %s" % str(e)
@@ -670,7 +670,7 @@ def list_headers(root): return (modules, support_macros) -def parse_headers(root, output=None, expand=True): +def parse_headers(root, output=None, expand=True, debug=False): import util headers = refpolicy.Headers()
@@ -696,11 +696,13 @@ def parse_headers(root, output=None, exp output.write(msg) def parse_file(f, module, spt=None): + if debug: + o("parsing file %s\n" % f) try: fd = open(f) txt = fd.read() fd.close() - parse(txt, module, spt) + parse(txt, module, spt, debug) except IOError, e: return except ValueError, e:
@@ -726,7 +728,7 @@ def parse_headers(root, output=None, exp o("done.\n") - if output: + if output and not debug: status = util.ConsoleProgressBar(sys.stdout, steps=len(modules)) status.start("Parsing interface files")
@@ -744,7 +746,7 @@ def parse_headers(root, output=None, exp continue headers.children.append(m) - if output: + if output and not debug: status.step() if len(failures):
Quoted 5 lines · Karl MacMillan
This patch allows a caller to request the output of debugging information from the parser. This is mainly useful for development / debugging of the parser.
Signed-off-by Karl MacMillan <[email protected]>
Thanks, merged.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.