mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 09:13:04 +01:00
sarif-to-dot: cleanup for and preparation for sarif table extraction
This commit is contained in:
committed by
=Michael Hohn
parent
c664ae2f8f
commit
cf8096446b
@@ -15,7 +15,8 @@ context = S.Context(
|
||||
"string" : "String",
|
||||
"int" : "Int",
|
||||
"bool" : "Bool"
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
parser = argparse.ArgumentParser(description='Produce a summary of signatures found in the sarif file.')
|
||||
parser.add_argument('file', metavar='sarif-file', type=str, help='input file, - for stdin')
|
||||
@@ -65,7 +66,7 @@ if args.dot_output:
|
||||
elif args.typedef_signatures:
|
||||
S._signature(args, sarif_struct, context)
|
||||
struct_graph = [(typedef, sig) for sig,typedef in context.sig_to_typedef.items()]
|
||||
pprint(struct_graph, sys.stdout, indent=2)
|
||||
pprint(struct_graph, sys.stdout, indent=4)
|
||||
|
||||
else:
|
||||
pprint(S._signature(args, sarif_struct, context), sys.stdout, indent=2)
|
||||
pprint(S._signature(args, sarif_struct, context), sys.stdout, indent=4)
|
||||
|
||||
Binary file not shown.
BIN
notes/sarif-structure-from-sarif-to-dot.pdf
Normal file
BIN
notes/sarif-structure-from-sarif-to-dot.pdf
Normal file
Binary file not shown.
@@ -30,16 +30,15 @@ import zlib
|
||||
#
|
||||
@dataclass
|
||||
class Context:
|
||||
sig_to_typedef: dict # signature to typedef name map
|
||||
sig_to_typedef: dict # signature -> typedef name map
|
||||
|
||||
def shorthash(signature):
|
||||
return zlib.adler32(str(signature).encode('utf-8')) % 10000
|
||||
|
||||
|
||||
#
|
||||
# Signature formation
|
||||
#
|
||||
def _signature_dict(args, elem, context):
|
||||
def _signature_dict(args, elem, context: Context):
|
||||
""" Assemble and return the signature for a dictionary.
|
||||
"""
|
||||
# Collect signatures
|
||||
@@ -55,8 +54,10 @@ def _signature_dict(args, elem, context):
|
||||
# Give every unique struct a name and use a reference to it as value.
|
||||
if signature not in context.sig_to_typedef:
|
||||
context.sig_to_typedef[signature] = "Struct%04d" % shorthash(signature)
|
||||
signature = context.sig_to_typedef[signature]
|
||||
return signature
|
||||
typedef = context.sig_to_typedef[signature]
|
||||
return typedef
|
||||
else:
|
||||
return signature
|
||||
|
||||
def _signature_list(args, elem, context):
|
||||
""" Assemble and return the signature for a Python list.
|
||||
@@ -79,8 +80,10 @@ def _signature_list(args, elem, context):
|
||||
# Give every unique array a name and use a reference to it as value.
|
||||
if signature not in context.sig_to_typedef:
|
||||
context.sig_to_typedef[signature] = "Array%04d" % shorthash(signature)
|
||||
signature = context.sig_to_typedef[signature]
|
||||
return signature
|
||||
typedef = context.sig_to_typedef[signature]
|
||||
return typedef
|
||||
else:
|
||||
return signature
|
||||
|
||||
def _signature(args, elem, context):
|
||||
""" Assemble and return the signature for a list/dict/value structure.
|
||||
|
||||
Reference in New Issue
Block a user