Add location information to boolean conditions in paths. Improves comprehension a little

Summary:
Show location of start of expression in boolean condition trace nodes.

closes #574

Reviewed By: jvillard

Differential Revision: D5121885

fbshipit-source-id: 4777e9e
master
Don Stewart 8 years ago committed by Facebook Github Bot
parent 750cc65092
commit 1a41d9dc89

@ -81,12 +81,14 @@ class Tracer(object):
return return
report_line = node[issues.JSON_INDEX_TRACE_LINE] report_line = node[issues.JSON_INDEX_TRACE_LINE]
report_col = node[issues.JSON_INDEX_TRACE_COLUMN]
fname = node[issues.JSON_INDEX_TRACE_FILENAME] fname = node[issues.JSON_INDEX_TRACE_FILENAME]
self.indenter.newline() self.indenter.newline()
self.indenter.add('%s:%d: %s' % ( self.indenter.add('%s:%d:%d: %s' % (
fname, fname,
report_line, report_line,
report_col,
node[issues.JSON_INDEX_TRACE_DESCRIPTION], node[issues.JSON_INDEX_TRACE_DESCRIPTION],
)) ))
self.indenter.newline() self.indenter.newline()
@ -96,9 +98,13 @@ class Tracer(object):
mode = colorize.TERMINAL_FORMATTER mode = colorize.TERMINAL_FORMATTER
if self.args.html: if self.args.html:
mode = colorize.PLAIN_FORMATTER mode = colorize.PLAIN_FORMATTER
empty_desc = len(node[issues.JSON_INDEX_TRACE_DESCRIPTION]) == 0
self.indenter.add(source.build_source_context(fname, self.indenter.add(source.build_source_context(fname,
mode, mode,
report_line)) report_line,
report_col,
empty_desc
))
self.indenter.indent_pop() self.indenter.indent_pop()
self.indenter.newline() self.indenter.newline()

@ -52,6 +52,7 @@ JSON_INDEX_TRACE = 'bug_trace'
JSON_INDEX_TRACE_LEVEL = 'level' JSON_INDEX_TRACE_LEVEL = 'level'
JSON_INDEX_TRACE_FILENAME = 'filename' JSON_INDEX_TRACE_FILENAME = 'filename'
JSON_INDEX_TRACE_LINE = 'line_number' JSON_INDEX_TRACE_LINE = 'line_number'
JSON_INDEX_TRACE_COLUMN = 'column_number'
JSON_INDEX_TRACE_DESCRIPTION = 'description' JSON_INDEX_TRACE_DESCRIPTION = 'description'
JSON_INDEX_TRACEVIEW_ID = 'traceview_id' JSON_INDEX_TRACEVIEW_ID = 'traceview_id'
JSON_INDEX_VISIBILITY = 'visibility' JSON_INDEX_VISIBILITY = 'visibility'
@ -110,6 +111,8 @@ def _text_of_report_list(project_root, reports, bugs_txt_path, limit=None,
os.path.join(project_root, filename), os.path.join(project_root, filename),
formatter, formatter,
line, line,
1,
True
) )
indenter = source.Indenter() \ indenter = source.Indenter() \
.indent_push() \ .indent_push() \

@ -60,8 +60,10 @@ class Indenter(unicode):
return utils.encode(unicode(self)) return utils.encode(unicode(self))
def build_source_context(source_name, mode, report_line): def build_source_context(source_name, mode, report_line,
report_col, empty_desc):
start_line = max(1, report_line - SOURCE_CONTEXT) start_line = max(1, report_line - SOURCE_CONTEXT)
start_col = max(0, report_col)
# could go beyond last line, checked in the loop # could go beyond last line, checked in the loop
end_line = report_line + SOURCE_CONTEXT end_line = report_line + SOURCE_CONTEXT
@ -91,10 +93,20 @@ def build_source_context(source_name, mode, report_line):
num = colorize.color((str(line_number) + '.').zfill(n_length), num = colorize.color((str(line_number) + '.').zfill(n_length),
colorize.DIM, mode) colorize.DIM, mode)
caret = ' ' caret = ' '
if line_number == report_line: do_mark_column = (line_number == report_line and
start_col > 1 and not empty_desc)
# mark the line if we are not also marking the column
if line_number == report_line and not do_mark_column:
caret = colorize.color('> ', caret = colorize.color('> ',
colorize.HEADER, mode) colorize.BLUE + colorize.BRIGHT, mode)
s += '%s %s%s\n' % (num, caret, line) s += '%s %s%s\n' % (num, caret, line)
# mark the column position
if do_mark_column:
pad = ' ' * (3 + n_length + start_col)
s += pad + colorize.color('^',
colorize.BLUE + colorize.BRIGHT,
mode) + '\n'
line_number += 1 line_number += 1
return s return s

@ -126,6 +126,7 @@ let loc_trace_to_jsonbug_record trace_list ekind =>
Jsonbug_j.level: trace_item.Errlog.lt_level, Jsonbug_j.level: trace_item.Errlog.lt_level,
filename: SourceFile.to_string trace_item.Errlog.lt_loc.Location.file, filename: SourceFile.to_string trace_item.Errlog.lt_loc.Location.file,
line_number: trace_item.Errlog.lt_loc.Location.line, line_number: trace_item.Errlog.lt_loc.Location.line,
column_number: trace_item.Errlog.lt_loc.Location.col,
description: trace_item.Errlog.lt_description, description: trace_item.Errlog.lt_description,
node_tags: List.concat_map f::tag_value_records_of_node_tag trace_item.Errlog.lt_node_tags node_tags: List.concat_map f::tag_value_records_of_node_tag trace_item.Errlog.lt_node_tags
}; };

@ -7,6 +7,7 @@ type json_trace_item = {
level : int; level : int;
filename : string; filename : string;
line_number : int; line_number : int;
column_number : int;
description : string; description : string;
node_tags : tag_value_record list; node_tags : tag_value_record list;
} }

@ -472,16 +472,20 @@ end = struct
trace := Errlog.make_trace_element level curr_loc descr node_tags :: !trace trace := Errlog.make_trace_element level curr_loc descr node_tags :: !trace
| Procdesc.Node.Prune_node (is_true_branch, if_kind, _) -> | Procdesc.Node.Prune_node (is_true_branch, if_kind, _) ->
let descr = match is_true_branch, if_kind with let descr = match is_true_branch, if_kind with
| true, Sil.Ik_if -> "Taking true branch" | true, Sil.Ik_if ->
| false, Sil.Ik_if -> "Taking false branch" "Taking true branch"
| false, Sil.Ik_if ->
"Taking false branch"
| true, (Sil.Ik_for | Sil.Ik_while | Sil.Ik_dowhile) -> | true, (Sil.Ik_for | Sil.Ik_while | Sil.Ik_dowhile) ->
"Loop condition is true. Entering loop body" "Loop condition is true. Entering loop body"
| false, (Sil.Ik_for | Sil.Ik_while | Sil.Ik_dowhile) -> | false, (Sil.Ik_for | Sil.Ik_while | Sil.Ik_dowhile) ->
"Loop condition is false. Leaving loop" "Loop condition is false. Leaving loop"
| true, Sil.Ik_switch -> "Switch condition is true. Entering switch case" | true, Sil.Ik_switch -> "Switch condition is true. Entering switch case"
| false, Sil.Ik_switch -> "Switch condition is false. Skipping switch case" | false, Sil.Ik_switch -> "Switch condition is false. Skipping switch case"
| true, (Sil.Ik_bexp | Sil.Ik_land_lor) -> "Condition is true" | true, (Sil.Ik_bexp | Sil.Ik_land_lor) ->
| false, (Sil.Ik_bexp | Sil.Ik_land_lor) -> "Condition is false" in "Condition is true"
| false, (Sil.Ik_bexp | Sil.Ik_land_lor) ->
"Condition is false" in
let node_tags = [Errlog.Condition is_true_branch] in let node_tags = [Errlog.Condition is_true_branch] in
trace := Errlog.make_trace_element level curr_loc descr node_tags :: !trace trace := Errlog.make_trace_element level curr_loc descr node_tags :: !trace
| Procdesc.Node.Exit_node pname -> | Procdesc.Node.Exit_node pname ->

Loading…
Cancel
Save