Skip to content

Commit

Permalink
[osh2oil refactor] spid -> Token APIs
Browse files Browse the repository at this point in the history
Other misc spid cleanups.

Move function to location.py
  • Loading branch information
Andy C committed May 21, 2023
1 parent e4abea9 commit c505411
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 155 deletions.
18 changes: 0 additions & 18 deletions core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,24 +709,6 @@ def ErrExitDisabledSpanId(self):

return self.errexit_disabled_tok[-1]

# Old complex logic. It turns out we don't need to detect whether it was
# actually disabled. These are the "strict_errexit without errexit" cases
# in spec/errexit-oil.
"""
overlay = self.opt_stacks[option_i.errexit]
# log('overlay %s', overlay)
# log('errexit_disabled_spid %s', self.errexit_disabled_spid)
if overlay is None or len(overlay) == 0:
return runtime.NO_SPID
else:
was_on = self.opt0_array[option_i.errexit] or (True in overlay)
# top of stack == False means it's disabled
if was_on and not overlay[-1]:
return self.errexit_disabled_spid[-1]
else:
return runtime.NO_SPID
"""

def _SetOldOption(self, opt_name, b):
# type: (str, bool) -> None
"""Private version for synchronizing from SHELLOPTS."""
Expand Down
24 changes: 24 additions & 0 deletions frontend/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from _devbuild.gen.syntax_asdl import (
loc, loc_t, loc_e,
command, command_e, command_t,
sh_lhs_expr, sh_lhs_expr_e, sh_lhs_expr_t,
word, word_e, word_t,
word_part, word_part_e, word_part_t,
CompoundWord, SimpleVarSub, Token,
Expand Down Expand Up @@ -401,3 +402,26 @@ def RightTokenForWord(w):
raise AssertionError(w.tag())

raise AssertionError('for -Wreturn-type in C++')


def TokenForLhsExpr(node):
# type: (sh_lhs_expr_t) -> Token
"""
Currently unused? Will be useful for translating YSH assignment
"""
# This switch is annoying but we don't have inheritance from the sum type
# (because of diamond issue). We might change the schema later, which maeks
# it moot. See the comment in frontend/syntax.asdl.
UP_node = node
with tagswitch(node) as case:
if case(sh_lhs_expr_e.Name):
node = cast(sh_lhs_expr.Name, UP_node)
return node.left
elif case(sh_lhs_expr_e.IndexedName):
node = cast(sh_lhs_expr.IndexedName, UP_node)
return node.left
else:
# Should not see UnparsedIndex
raise AssertionError()

raise AssertionError()
24 changes: 0 additions & 24 deletions osh/word_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Token, CompoundWord, DoubleQuoted, SingleQuoted,
word, word_e, word_t, word_str,
word_part, word_part_t, word_part_e,
sh_lhs_expr, sh_lhs_expr_e, sh_lhs_expr_t,
AssocPair,
)
from mycpp.mylib import log
Expand Down Expand Up @@ -587,29 +586,6 @@ def IsVarSub(w):
return False


def SpanForLhsExpr(node):
# type: (sh_lhs_expr_t) -> int
"""
Currently unused? Will be useful for translating YSH assignment
"""
# This switch is annoying but we don't have inheritance from the sum type
# (because of diamond issue). We might change the schema later, which maeks
# it moot. See the comment in frontend/syntax.asdl.
UP_node = node
with tagswitch(node) as case:
if case(sh_lhs_expr_e.Name):
node = cast(sh_lhs_expr.Name, UP_node)
return node.left.span_id
elif case(sh_lhs_expr_e.IndexedName):
node = cast(sh_lhs_expr.IndexedName, UP_node)
return node.left.span_id
else:
# Should not see UnparsedIndex
raise AssertionError()

raise AssertionError()


# Doesn't translate with mycpp because of dynamic %
def ErrorWord(error_str):
# type: (str) -> CompoundWord
Expand Down

0 comments on commit c505411

Please sign in to comment.