-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[refactor] Type-driven refactoring: remove span_id in PrefixPrint() #1491
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
from _devbuild.gen.id_kind_asdl import Id, Id_t, Id_str | ||
from _devbuild.gen.syntax_asdl import ( | ||
Token, SourceLine, command_t, command_str, | ||
loc_t, Token, SourceLine, command_t, command_str, | ||
source_e, source__Stdin, source__MainFile, source__SourcedFile, | ||
source__Alias, source__Reparsed, source__Variable, source__VarRef, | ||
source__ArgvWord, source__Synthetic | ||
|
@@ -304,9 +304,10 @@ def CurrentLocation(self): | |
else: | ||
return runtime.NO_SPID | ||
|
||
def PrefixPrint(self, msg, prefix, span_id=runtime.NO_SPID): | ||
# type: (str, str, int) -> None | ||
def PrefixPrint(self, msg, prefix, blame_loc): | ||
# type: (str, str, loc_t) -> None | ||
"""Print a hard-coded message with a prefix, and quote code.""" | ||
span_id = location.GetSpanId(blame_loc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can use our function to convert a loc_t to a span_id Later will remove it from this internal function, but for now it lets us make a small diff |
||
_PrintWithSpanId(prefix, msg, span_id, self.arena, show_code=True) | ||
|
||
def Print_(self, msg, span_id=runtime.NO_SPID): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,7 +316,7 @@ def _RunAssignBuiltin(self, cmd_val): | |
arg0 = cmd_val.argv[0] | ||
if e.span_id == runtime.NO_SPID: # fill in default location. | ||
e.span_id = self.errfmt.CurrentLocation() | ||
self.errfmt.PrefixPrint(e.msg, prefix='%r ' % arg0, span_id=e.span_id) | ||
self.errfmt.PrefixPrint(e.msg, '%r ' % arg0, loc.Span(e.span_id)) | ||
status = 2 # consistent error code for usage error | ||
|
||
return status | ||
|
@@ -1046,7 +1046,7 @@ def _Dispatch(self, node, cmd_st): | |
else: | ||
# Only print warnings, never fatal. | ||
# Bash oddly only exits 1 for 'return', but no other shell does. | ||
self.errfmt.PrefixPrint(msg, prefix='warning: ', span_id=tok.span_id) | ||
self.errfmt.PrefixPrint(msg, 'warning: ', tok) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we do NOT pass Remember that a Token is a location Anywhere you would see That's like doing a "double conversion" and is not necessary |
||
status = 0 | ||
|
||
# Note CommandList and DoGroup have no redirects, but BraceGroup does. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the common case: simply wrap span ID in
loc.Span()