← Back
Editing: ast_transforms.cpython-312.pyc
� ��_^@ � � � d dl mZ d� Zd� Zy)� )�c_astc �v � t | t j � sJ �t | j t j � s| S t j g | j j � }d}| j j xs g D ]� }t |t j t j f� rA|j j |� t ||j � |j d }�n|�|j j |� ��|j j |� �� || _ | S )a� The 'case' statements in a 'switch' come out of parsing with one child node, so subsequent statements are just tucked to the parent Compound. Additionally, consecutive (fall-through) case statements come out messy. This is a peculiarity of the C grammar. The following: switch (myvar) { case 10: k = 10; p = k + 1; return 10; case 20: case 30: return 20; default: break; } Creates this tree (pseudo-dump): Switch ID: myvar Compound: Case 10: k = 10 p = k + 1 return 10 Case 20: Case 30: return 20 Default: break The goal of this transform is to fix this mess, turning it into the following: Switch ID: myvar Compound: Case 10: k = 10 p = k + 1 return 10 Case 20: Case 30: return 20 Default: break A fixed AST node is returned. The argument may be modified. N���)� isinstancer �Switch�stmt�Compound�coord�block_items�Case�Default�append�_extract_nested_case�stmts)�switch_node�new_compound� last_case�childs �=/usr/lib/python3.12/site-packages/pycparser/ast_transforms.py�fix_switch_casesr s � �f �k�5�<�<�0�0�0��k�&�&����7��� �>�>�"�k�&6�&6�&<�&<�=�L� �I� �"�"�.�.�4�"�4���e�e�j�j�%�-�-�8�9� �$�$�+�+�E�2� ���(@�(@�A�$�0�0��4�I� � ��(�(�/�/��6����&�&�u�-� 5�"