mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-17 01:23:04 +01:00
sarif-to-dot: to reduce graph clutter, add option --no-edges-to-scalars
This commit is contained in:
committed by
=Michael Hohn
parent
d7d566c5db
commit
153eba8346
@@ -26,9 +26,15 @@ parser.add_argument('-t', '--typedef-signatures', action="store_true",
|
|||||||
help='Give every object signature a type and report by types')
|
help='Give every object signature a type and report by types')
|
||||||
parser.add_argument('-d', '--dot-output', action="store_true",
|
parser.add_argument('-d', '--dot-output', action="store_true",
|
||||||
help='Output type table as dot graph. Implies -t -u')
|
help='Output type table as dot graph. Implies -t -u')
|
||||||
|
parser.add_argument('-n', '--no-edges-to-scalars', action="store_true",
|
||||||
|
help='Suppress edges to int/bool/string types in dot graph. Implies -d')
|
||||||
parser.add_argument('-f', '--fill-structure', action="store_true",
|
parser.add_argument('-f', '--fill-structure', action="store_true",
|
||||||
help='Fill in missing (optional) entries in sarif input before other steps.')
|
help='Fill in missing (optional) entries in sarif input before other steps.')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.no_edges_to_scalars:
|
||||||
|
args.dot_output = True
|
||||||
|
|
||||||
if args.dot_output:
|
if args.dot_output:
|
||||||
args.unique_array_signatures = True
|
args.unique_array_signatures = True
|
||||||
args.typedef_signatures = True
|
args.typedef_signatures = True
|
||||||
@@ -54,7 +60,7 @@ if args.dot_output:
|
|||||||
for typedef, sig in struct_graph:
|
for typedef, sig in struct_graph:
|
||||||
S.write_node(sys.stdout, typedef, sig)
|
S.write_node(sys.stdout, typedef, sig)
|
||||||
for typedef, sig in struct_graph:
|
for typedef, sig in struct_graph:
|
||||||
S.write_edges(sys.stdout, typedef, sig)
|
S.write_edges(args, sys.stdout, typedef, sig)
|
||||||
S.write_footer(sys.stdout)
|
S.write_footer(sys.stdout)
|
||||||
|
|
||||||
elif args.typedef_signatures:
|
elif args.typedef_signatures:
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ def write_node(fp, typedef, sig):
|
|||||||
""".format(name=typedef, head=typedef, body=label)
|
""".format(name=typedef, head=typedef, body=label)
|
||||||
fp.write(node)
|
fp.write(node)
|
||||||
|
|
||||||
def write_edges(fp, typedef, sig):
|
def write_edges(args, fp, typedef, sig):
|
||||||
""" Write edges in dot format.
|
""" Write edges in dot format.
|
||||||
"""
|
"""
|
||||||
if sig in ["string", "int", "bool"]:
|
if sig in ["string", "int", "bool"]:
|
||||||
@@ -158,10 +158,13 @@ def write_edges(fp, typedef, sig):
|
|||||||
field_name, field_type = field
|
field_name, field_type = field
|
||||||
label = ""
|
label = ""
|
||||||
dest = str(field_type)
|
dest = str(field_type)
|
||||||
edge = """ {src_node}:"{src_port}" -> {dest} [label="{label}"];
|
if dest in ["String", "Int", "Bool"] and args.no_edges_to_scalars:
|
||||||
""".format(src_node=typedef, src_port=field_name, dest=field_type,
|
pass
|
||||||
label=label)
|
else:
|
||||||
fp.write(edge)
|
edge = """ {src_node}:"{src_port}" -> {dest} [label="{label}"];
|
||||||
|
""".format(src_node=typedef, src_port=field_name, dest=field_type,
|
||||||
|
label=label)
|
||||||
|
fp.write(edge)
|
||||||
else:
|
else:
|
||||||
raise Exception("unknown signature: " + str(sig))
|
raise Exception("unknown signature: " + str(sig))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user