diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-04-18 16:11:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 16:11:48 (GMT) |
commit | bfda4db0d2c05eef4e4ae90d899d0b67cb2e33e5 (patch) | |
tree | eb56e770c258a8310aec4a2680ad06bf26da16a4 /Tools | |
parent | 904dd068fb6dc9a70f30dc46061e8b57d7797119 (diff) | |
download | cpython-bfda4db0d2c05eef4e4ae90d899d0b67cb2e33e5.zip cpython-bfda4db0d2c05eef4e4ae90d899d0b67cb2e33e5.tar.gz cpython-bfda4db0d2c05eef4e4ae90d899d0b67cb2e33e5.tar.bz2 |
[3.8] bpo-40179: Fix translation of #elif in Argument Clinic (GH-19364) (GH-19583)
Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
(cherry picked from commit 12446e6a605f066d837d3a595d0a73e4f3b43b65)
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/clinic/cpp.py | 37 |
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()) |