bpo-40179: Fix translation of #elif in Argument Clinic (GH-19364)

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
This commit is contained in:
Serhiy Storchaka 2020-04-18 17:52:48 +03:00 committed by GitHub
parent fb940408ce
commit 12446e6a60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 126 additions and 25 deletions

View file

@ -141,23 +141,15 @@ class Monitor:
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:
@ -166,18 +158,21 @@ class Monitor:
condition = 'defined(' + symbol + ')'
if token == 'ifndef':
condition = '!' + condition
token = 'if'
self.stack.append(("if", condition))
if self.verbose:
print(self.status())
self.stack.append((token, condition))
elif token == 'else':
previous_token, previous_condition = pop_stack()
self.stack.append((previous_token, negate(previous_condition)))
elif token == 'endif':
while pop_stack()[0] != 'if':
pass
else:
return
previous_token, previous_condition = pop_stack()
if token == 'else':
self.stack.append(('else', negate(previous_condition)))
elif token == 'endif':
pass
if self.verbose:
print(self.status())