summaryrefslogtreecommitdiffstats
path: root/Tools/clinic
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-04-18 14:52:48 (GMT)
committerGitHub <noreply@github.com>2020-04-18 14:52:48 (GMT)
commit12446e6a605f066d837d3a595d0a73e4f3b43b65 (patch)
tree37e77c25412fea6c90235bcca453d3a6225e00cb /Tools/clinic
parentfb940408cea1fb34fed1418832f240f886dadf57 (diff)
downloadcpython-12446e6a605f066d837d3a595d0a73e4f3b43b65.zip
cpython-12446e6a605f066d837d3a595d0a73e4f3b43b65.tar.gz
cpython-12446e6a605f066d837d3a595d0a73e4f3b43b65.tar.bz2
bpo-40179: Fix translation of #elif in Argument Clinic (GH-19364)
Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
Diffstat (limited to 'Tools/clinic')
-rw-r--r--Tools/clinic/cpp.py37
1 files changed, 16 insertions, 21 deletions
diff --git a/Tools/clinic/cpp.py b/Tools/clinic/cpp.py
index e099590..77f5f96 100644
--- a/Tools/clinic/cpp.py
+++ b/Tools/clinic/cpp.py
@@ -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())
- 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())