Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed translation of ``#elif`` in Argument Clinic.
14 changes: 7 additions & 7 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 16 additions & 21 deletions Tools/clinic/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,15 @@ def pop_stack():
token = fields[0].lower()
condition = ' '.join(fields[1:]).strip()

if_tokens = {'if', 'ifdef', 'ifndef'}
all_tokens = if_tokens | {'elif', 'else', 'endif'}

if token not in all_tokens:
return

# cheat a little here, to reuse the implementation of if
if token == 'elif':
pop_stack()
token = 'if'

if token in if_tokens:
if token in {'if', 'ifdef', 'ifndef', 'elif'}:
if not condition:
self.fail("Invalid format for #" + token + " line: no argument!")
if token == 'if':
if token in {'if', 'elif'}:
if not self.is_a_simple_defined(condition):
condition = "(" + condition + ")"
if token == 'elif':
previous_token, previous_condition = pop_stack()
self.stack.append((previous_token, negate(previous_condition)))
else:
fields = condition.split()
if len(fields) != 1:
Expand All @@ -166,18 +158,21 @@ def pop_stack():
condition = 'defined(' + symbol + ')'
if token == 'ifndef':
condition = '!' + condition
token = 'if'

self.stack.append(("if", condition))
if self.verbose:
print(self.status())
return
self.stack.append((token, condition))

previous_token, previous_condition = pop_stack()
elif token == 'else':
previous_token, previous_condition = pop_stack()
self.stack.append((previous_token, negate(previous_condition)))

if token == 'else':
self.stack.append(('else', negate(previous_condition)))
elif token == 'endif':
pass
while pop_stack()[0] != 'if':
pass

else:
return

if self.verbose:
print(self.status())

Expand Down