mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
sarif-to-dot: small renaming
This commit is contained in:
committed by
=Michael Hohn
parent
939ba9bd8a
commit
86caa3f56f
@@ -13,13 +13,13 @@ class Context:
|
||||
sig_to_typedef: dict # signature to typedef name map
|
||||
sig_count: int # simple struct counter for Struct%03d names
|
||||
|
||||
def _traverse_dict(elem, context):
|
||||
def _signature_dict(elem, context):
|
||||
""" Assemble and return the signature for a dictionary.
|
||||
"""
|
||||
# Collect signatures
|
||||
sig = {}
|
||||
for key, val in elem.items():
|
||||
sig[key] = _traverse(val, context)
|
||||
sig[key] = _signature(val, context)
|
||||
# Sort signature
|
||||
keys = list(elem.keys())
|
||||
keys.sort()
|
||||
@@ -33,14 +33,14 @@ def _traverse_dict(elem, context):
|
||||
signature = context.sig_to_typedef[signature]
|
||||
return signature
|
||||
|
||||
def _traverse_list(elem, context):
|
||||
def _signature_list(elem, context):
|
||||
""" Assemble and return the signature for a Python list.
|
||||
"""
|
||||
if args.unique_array_signatures:
|
||||
# Collect all unique signatures
|
||||
sig = set()
|
||||
for el in elem:
|
||||
sig.add(_traverse(el, context))
|
||||
sig.add(_signature(el, context))
|
||||
sig = list(sig)
|
||||
sig.sort()
|
||||
signature = ("array", ) + tuple([(i, s) for (i, s) in enumerate(sig)])
|
||||
@@ -48,7 +48,7 @@ def _traverse_list(elem, context):
|
||||
# Collect all signatures
|
||||
sig = []
|
||||
for el in elem:
|
||||
sig.append(_traverse(el, context))
|
||||
sig.append(_signature(el, context))
|
||||
signature = ("array", ) + tuple([(i, s) for (i, s) in enumerate(sig)])
|
||||
if args.typedef_signatures:
|
||||
# Give every unique array a name and use a reference to it as value.
|
||||
@@ -58,14 +58,14 @@ def _traverse_list(elem, context):
|
||||
signature = context.sig_to_typedef[signature]
|
||||
return signature
|
||||
|
||||
def _traverse(elem, context):
|
||||
""" Traverse the list/dict/value structure.
|
||||
def _signature(elem, context):
|
||||
""" Assemble and return the signature for a list/dict/value structure.
|
||||
"""
|
||||
t = type(elem)
|
||||
if t == dict:
|
||||
return _traverse_dict(elem, context)
|
||||
return _signature_dict(elem, context)
|
||||
elif t == list:
|
||||
return _traverse_list(elem, context)
|
||||
return _signature_list(elem, context)
|
||||
elif t == str:
|
||||
if args.typedef_signatures:
|
||||
return context.sig_to_typedef["string"]
|
||||
@@ -185,7 +185,7 @@ with open(args.file, 'r') if args.file != '-' else sys.stdin as fp:
|
||||
sarif_struct = json.load(fp)
|
||||
|
||||
if args.dot_output:
|
||||
_traverse(sarif_struct, context)
|
||||
_signature(sarif_struct, context)
|
||||
struct_graph = [(typedef, sig) for sig, typedef in context.sig_to_typedef.items()]
|
||||
write_header(sys.stdout)
|
||||
for typedef, sig in struct_graph:
|
||||
@@ -195,8 +195,8 @@ if args.dot_output:
|
||||
write_footer(sys.stdout)
|
||||
|
||||
elif args.typedef_signatures:
|
||||
_traverse(sarif_struct, context)
|
||||
_signature(sarif_struct, context)
|
||||
struct_graph = [(typedef, sig) for sig,typedef in context.sig_to_typedef.items()]
|
||||
pprint(struct_graph, sys.stdout, indent=2)
|
||||
else:
|
||||
pprint(_traverse(sarif_struct, context), sys.stdout, indent=2)
|
||||
pprint(_signature(sarif_struct, context), sys.stdout, indent=2)
|
||||
|
||||
Reference in New Issue
Block a user