Skip to content

Commit 43ad0f2

Browse files
author
Andy C
committed
[translation] Fix conflict with --extern flag and C++ extern keyword
Rename me -> self_val
1 parent b872fc7 commit 43ad0f2

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

builtin/meta_osh.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ class Invoke(vm._Builtin):
410410
invoke --builtin
411411
invoke --builtin true
412412
"""
413+
413414
def __init__(self, shell_ex, procs, errfmt):
414415
# type: (vm._Executor, state.Procs, ui.ErrorFormatter) -> None
415416
self.shell_ex = shell_ex

frontend/flag_def.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,9 @@ def _DefineCompletionActions(spec):
468468
RUNPROC_SPEC.ShortFlag('-h', args.Bool, help='Show all procs')
469469

470470
INVOKE_SPEC = FlagSpec('invoke')
471-
472-
# 3 coarse-grained categories.
473-
INVOKE_SPEC.LongFlag('--builtin') # like 'builtin', which includs special builtins
474-
INVOKE_SPEC.LongFlag('--proc-like') # like 'runproc' - proc, sh func, or invokable obj
475-
INVOKE_SPEC.LongFlag('--extern') # like 'extern' builtin
471+
INVOKE_SPEC.LongFlag('--builtin') # like 'builtin'
472+
INVOKE_SPEC.LongFlag('--proc-like') # like 'runproc'
473+
INVOKE_SPEC.LongFlag('--extern') # like 'extern'
476474

477475
EXTERN_SPEC = FlagSpec('extern')
478476

frontend/flag_gen.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python2
2-
"""Flag_gen.py."""
2+
""" flag_gen.py - generate Python and C++ from flag specs """
33
from __future__ import print_function
44

55
import itertools
@@ -32,6 +32,14 @@ def CString(s):
3232
return '"%s"' % s
3333

3434

35+
def _CleanFieldName(name):
36+
# Avoid C++ keyword for invoke --extern
37+
if name == 'extern':
38+
return 'extern_'
39+
40+
return name.replace('-', '_')
41+
42+
3543
def _WriteStrArray(f, var_name, a):
3644
c_strs = ', '.join(CString(s) for s in sorted(a))
3745
f.write('const char* %s[] = {%s, nullptr};\n' % (var_name, c_strs))
@@ -206,7 +214,7 @@ def Cpp(specs, header_f, cc_f):
206214
bits = []
207215
for field_name in sorted(spec.fields):
208216
typ = spec.fields[field_name]
209-
field_name = field_name.replace('-', '_')
217+
field_name = _CleanFieldName(field_name)
210218
field_names.append(field_name)
211219

212220
with switch(typ) as case:
@@ -485,7 +493,7 @@ def __init__(self, attrs):
485493
i = 0
486494
for field_name in sorted(spec.fields):
487495
typ = spec.fields[field_name]
488-
field_name = field_name.replace('-', '_')
496+
field_name = _CleanFieldName(field_name)
489497

490498
with switch(typ) as case:
491499
if case(flag_type_e.Bool):

osh/cmd_eval.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,8 +2207,8 @@ def _MaybeRunErrTrap(self):
22072207
with state.ctx_ErrTrap(self.mem):
22082208
self._Execute(node)
22092209

2210-
def RunProc(self, proc, cmd_val):
2211-
# type: (value.Proc, cmd_value.Argv) -> int
2210+
def RunProc(self, proc, cmd_val, self_val=None):
2211+
# type: (value.Proc, cmd_value.Argv, value_t) -> int
22122212
"""Run procs aka "shell functions".
22132213
22142214
For SimpleCommand and registered completion hooks.
@@ -2222,7 +2222,7 @@ def RunProc(self, proc, cmd_val):
22222222

22232223
# Hm this sets "$@". TODO: Set ARGV only
22242224
with state.ctx_ProcCall(self.mem, self.mutable_opts, proc, proc_argv):
2225-
func_proc.BindProcArgs(proc, cmd_val, self.mem)
2225+
func_proc.BindProcArgs(proc, cmd_val, self.mem, self_val=self_val)
22262226

22272227
# Redirects still valid for functions.
22282228
# Here doc causes a pipe and Process(SubProgramThunk).

ysh/expr_eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ def _EvalFuncCall(self, node):
863863
to_call = func.func
864864
pos_args, named_args = func_proc._EvalArgList(self,
865865
node.args,
866-
me=func.me)
866+
self_val=func.me)
867867
rd = typed_args.Reader(pos_args,
868868
named_args,
869869
None,

ysh/func_proc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _EvalNamedArgs(expr_ev, named_exprs):
180180
def _EvalArgList(
181181
expr_ev, # type: expr_eval.ExprEvaluator
182182
args, # type: ArgList
183-
me=None # type: Optional[value_t]
183+
self_val=None # type: Optional[value_t]
184184
):
185185
# type: (...) -> Tuple[List[value_t], Optional[Dict[str, value_t]]]
186186
"""Evaluate arg list for funcs.
@@ -195,8 +195,8 @@ def _EvalArgList(
195195
"""
196196
pos_args = [] # type: List[value_t]
197197

198-
if me: # self/this argument
199-
pos_args.append(me)
198+
if self_val: # self/this argument
199+
pos_args.append(self_val)
200200

201201
_EvalPosArgs(expr_ev, args.pos_args, pos_args)
202202

@@ -451,8 +451,8 @@ def _BindFuncArgs(func, rd, mem):
451451
(func.name, num_named), blame_loc)
452452

453453

454-
def BindProcArgs(proc, cmd_val, mem):
455-
# type: (value.Proc, cmd_value.Argv, state.Mem) -> None
454+
def BindProcArgs(proc, cmd_val, mem, self_val=None):
455+
# type: (value.Proc, cmd_value.Argv, state.Mem, value_t) -> None
456456

457457
proc_args = cmd_val.proc_args
458458

@@ -489,7 +489,8 @@ def BindProcArgs(proc, cmd_val, mem):
489489
blame_loc = proc_args.typed_args.left
490490

491491
pos_args = proc_args.pos_args if proc_args else None
492-
if sig.positional: # or sig.block_param:
492+
if sig.positional:
493+
# TODO: Add self_val
493494
_BindTyped(proc.name, sig.positional, proc.defaults.for_typed,
494495
pos_args, mem, blame_loc)
495496
else:

0 commit comments

Comments
 (0)