Skip to content

Commit

Permalink
[refactor] Remove arena argument
Browse files Browse the repository at this point in the history
We got enough of the "big parser refactoring" done!
  • Loading branch information
Andy C committed May 21, 2023
1 parent 9e86d5a commit e4abea9
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bin/osh_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def ParseWholeFile(c_parser):
def main(argv):
# type: (List[str]) -> int
arena = alloc.Arena()
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()

opt0_array = state.InitOpts()
no_stack = None # type: List[bool] # for mycpp
Expand Down
2 changes: 1 addition & 1 deletion core/process_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def setUp(self):
self.tracer = dev.Tracer(None, exec_opts, mutable_opts, mem, mylib.Stderr())
self.waiter = process.Waiter(
self.job_list, exec_opts, self.trap_state, self.tracer)
errfmt = ui.ErrorFormatter(self.arena)
errfmt = ui.ErrorFormatter()
self.fd_state = process.FdState(errfmt, self.job_control, self.job_list,
None, self.tracer, None)
self.ext_prog = process.ExternalProgram('', self.fd_state, errfmt,
Expand Down
2 changes: 1 addition & 1 deletion core/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def Main(lang, arg_r, environ, login_shell, loader, readline):
flag = arg_types.main(attrs.attrs)

arena = alloc.Arena()
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()

help_builtin = builtin_misc.Help(loader, errfmt)
if flag.help:
Expand Down
6 changes: 3 additions & 3 deletions core/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def InitWordEvaluator(exec_opts=None):
cmd_deps.trap_nodes = []

splitter = split.SplitContext(mem)
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()

tilde_ev = word_eval.TildeEvaluator(mem, exec_opts)
ev = word_eval.CompletionWordEvaluator(mem, exec_opts, mutable_opts,
Expand Down Expand Up @@ -183,7 +183,7 @@ def InitCommandEvaluator(

# No 'readline' in the tests.

errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()
job_control = process.JobControl()
job_list = process.JobList()
fd_state = process.FdState(errfmt, job_control, job_list, None, None, None)
Expand Down Expand Up @@ -279,7 +279,7 @@ def EvalCode(code_str, parse_ctx, comp_lookup=None, mem=None, aliases=None):
CommandEvaluator.
"""
arena = parse_ctx.arena
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()

comp_lookup = comp_lookup or completion.Lookup()
mem = mem or state.Mem('', [], arena, [])
Expand Down
12 changes: 5 additions & 7 deletions core/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from typing import List, Optional, Any, cast, TYPE_CHECKING
if TYPE_CHECKING:
from _devbuild.gen import arg_types
from core.alloc import Arena
from core import error
from core.error import _ErrorWithLocation
from mycpp.mylib import Writer
Expand Down Expand Up @@ -285,17 +284,16 @@ class ErrorFormatter(object):
quotations. (TODO: turn off in child processes?)
"""

def __init__(self, arena):
# type: (Arena) -> None
self.arena = arena
self.last_spid = loc.Missing # last resort for location info
def __init__(self):
# type: () -> None
self.loc_stack = [] # type: List[loc_t]

self.one_line_errexit = False # root process

def OneLineErrExit(self):
# type: () -> None
"""Used by SubprogramThunk."""
"""Unused now
For SubprogramThunk."""
self.one_line_errexit = True

# A stack used for the current builtin. A fallback for UsageError.
Expand Down
2 changes: 1 addition & 1 deletion core/ui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def testErrorFormatter(self):
tok1 = arena.GetToken(spid1)
tok2 = arena.GetToken(spid2)

errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()

# no location info
errfmt.Print_('hello')
Expand Down
2 changes: 1 addition & 1 deletion osh/arith_parse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def ParseAndEval(code_str):
state.InitMem(mem, {}, '0.1')

splitter = split.SplitContext(mem)
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()

tilde_ev = word_eval.TildeEvaluator(mem, exec_opts)
word_ev = word_eval.CompletionWordEvaluator(mem, exec_opts, mutable_opts,
Expand Down
2 changes: 1 addition & 1 deletion osh/builtin_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _TestHistory(argv):
f = cStringIO.StringIO()
arena = alloc.Arena()
mem = state.Mem('', [], arena, [])
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()
b = builtin_lib.History(readline, mem, errfmt, f)
cmd_val = test_lib.MakeBuiltinArgv(argv)
b.Run(cmd_val)
Expand Down
2 changes: 1 addition & 1 deletion osh/builtin_printf.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def Run(self, cmd_val):
#log('fmt %s', fmt)
#log('vals %s', vals)

arena = self.errfmt.arena
arena = self.parse_ctx.arena
if fmt in self.parse_cache:
parts = self.parse_cache[fmt]
else:
Expand Down
4 changes: 2 additions & 2 deletions osh/cmd_parse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def _assertParseMethod(test, code_str, method, expect_success=True):
arena = test_lib.MakeArena('<cmd_parse_test>')
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()
c_parser = test_lib.InitCommandParser(code_str, arena=arena)
m = getattr(c_parser, method)
try:
Expand All @@ -37,7 +37,7 @@ def _assertParseMethod(test, code_str, method, expect_success=True):

def _assert_ParseCommandListError(test, code_str):
arena = test_lib.MakeArena('<cmd_parse_test>')
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()
c_parser = test_lib.InitCommandParser(code_str, arena=arena)

try:
Expand Down
2 changes: 1 addition & 1 deletion tea/tea_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def Main(arg_r):
arg = arg_types.tea_main(attrs.attrs)

arena = alloc.Arena()
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()

if arg.c is not None:
arena.PushSource(source.CFlag)
Expand Down
2 changes: 1 addition & 1 deletion tools/tools_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def OshCommandMain(argv):
return 0

arena = alloc.Arena(save_tokens=True)
errfmt = ui.ErrorFormatter(arena)
errfmt = ui.ErrorFormatter()
try:
script_name = argv[1]
arena.PushSource(source.MainFile(script_name))
Expand Down

0 comments on commit e4abea9

Please sign in to comment.