Skip to content

Commit

Permalink
[rename] Use location.OfX() pattern consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy C committed May 13, 2023
1 parent 8934fef commit dd83eab
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions core/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def RunPipeline(self, node, status_out):
child = node.children[i]

# TODO: determine these locations at parse time?
pipe_locs.append(location.LocForCommand(child))
pipe_locs.append(location.OfCommand(child))

p = self._MakeProcess(child)
p.Init_ParentPipeline(pi)
Expand All @@ -398,7 +398,7 @@ def RunPipeline(self, node, status_out):
last_child = node.children[n-1]
# Last piece of code is in THIS PROCESS. 'echo foo | read line; echo $line'
pi.AddLast((self.cmd_ev, last_child))
pipe_locs.append(location.LocForCommand(last_child))
pipe_locs.append(location.OfCommand(last_child))

with dev.ctx_Tracer(self.tracer, 'pipeline', None):
pi.StartPipeline(self.waiter)
Expand Down
4 changes: 2 additions & 2 deletions frontend/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def GetSpanId(loc_):
raise AssertionError()


def LocForCommand(node):
def OfCommand(node):
# type: (command_t) -> loc_t
"""
"""
Expand Down Expand Up @@ -131,7 +131,7 @@ def LocForCommand(node):
return loc.Missing


def LocForArithExpr(node):
def OfArithExpr(node):
# type: (arith_expr_t) -> loc_t
UP_node = node
with tagswitch(node) as case:
Expand Down
12 changes: 6 additions & 6 deletions osh/cmd_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _RunAssignBuiltin(self, cmd_val):

# TODO: Also change to BareAssign (set global or mutate local) and
# KeywordAssign. The latter may have flags too.
def _LocForShAssignment(self, node):
def _ShAssignLoc(self, node):
# type: (command.ShAssignment) -> loc_t
# TODO: Share with tracing (SetCurrentSpanId) and _CheckStatus
return loc.Span(node.spids[0])
Expand Down Expand Up @@ -368,15 +368,15 @@ def _CheckStatus(self, status, cmd_st, node, default_loc):
# ls *Z # error.FailGlob
# sort <(ls /x) # process sub failure
desc = 'Command'
blame_loc = location.LocForCommand(node)
blame_loc = location.OfCommand(node)

elif case(command_e.ShAssignment):
node = cast(command.ShAssignment, UP_node)
cmd_st.show_code = True # leaf
# Note: This happens rarely: when errexit and inherit_errexit are on,
# but command_sub_errexit is off!
desc = 'Assignment'
blame_loc = self._LocForShAssignment(node)
blame_loc = self._ShAssignLoc(node)

# Note: a subshell often doesn't fail on its own.
elif case(command_e.Subshell):
Expand Down Expand Up @@ -595,7 +595,7 @@ def _StrictErrExit(self, node):
if _HasManyStatuses(node):
node_str = ui.CommandType(node)
e_die("strict_errexit only allows simple commands in conditionals (got %s). " %
node_str, location.LocForCommand(node))
node_str, location.OfCommand(node))

def _StrictErrExitList(self, node_list):
# type: (List[command_t]) -> None
Expand All @@ -611,14 +611,14 @@ def _StrictErrExitList(self, node_list):

if len(node_list) > 1:
e_die("strict_errexit only allows a single command. Hint: use 'try'.",
location.LocForCommand(node_list[0]))
location.OfCommand(node_list[0]))

assert len(node_list) > 0
node = node_list[0]
if _HasManyStatuses(node): # TODO: consolidate error message with above
node_str = ui.CommandType(node)
e_die("strict_errexit only allows simple commands in conditionals (got %s). " %
node_str, location.LocForCommand(node))
node_str, location.OfCommand(node))

def _EvalCondition(self, cond, spid):
# type: (condition_t, int) -> bool
Expand Down
8 changes: 4 additions & 4 deletions osh/sh_expr_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def _EvalLhsAndLookupArith(self, node):
#if val.tag() == value_e.MaybeStrArray:
# e_die("Can't use assignment like ++ or += on arrays")

expr_loc = location.LocForArithExpr(node)
expr_loc = location.OfArithExpr(node)
i = self._ValToIntOrError(val, expr_loc)
return i, lval

Expand All @@ -471,7 +471,7 @@ def EvalToInt(self, node):
val = word_eval.DecayArray(val)

# TODO: Can we avoid the runtime cost of adding location info?
expr_loc = location.LocForArithExpr(node)
expr_loc = location.OfArithExpr(node)
i = self._ValToIntOrError(val, expr_loc)
return i

Expand Down Expand Up @@ -676,14 +676,14 @@ def Eval(self, node):
if rhs == 0:
# TODO: Could also blame /
e_die('Divide by zero',
location.LocForArithExpr(node.right))
location.OfArithExpr(node.right))

ret = lhs / rhs

elif op_id == Id.Arith_Percent:
if rhs == 0:
# TODO: Could also blame /
e_die('Divide by zero', location.LocForArithExpr(node.right))
e_die('Divide by zero', location.OfArithExpr(node.right))

ret = lhs % rhs

Expand Down
2 changes: 1 addition & 1 deletion tools/osh2oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def DoCommand(self, node, local_symbols, at_top_level=False):

# note: command_t doesn't have .spids
self.cursor.SkipUntil(
location.GetSpanId(location.LocForCommand(node.body)))
location.GetSpanId(location.OfCommand(node.body)))

elif case(for_iter_e.Words):
iterable = cast(for_iter.Words, UP_iterable)
Expand Down

0 comments on commit dd83eab

Please sign in to comment.