/ lib / pycparser / ast_transforms.pyc
ast_transforms.pyc
 1  o

 2  U��c;�@s0ddlmZdd�Zdd�Zdd�Zdd	�Zd
 3  S)�)�c_astcCs�t|tj�sJ�t|jtj�s|St�g|jj�}d}|jjp gD].}t|tjtjf�r>|j�	|�t
 4  ||j�|jd}q!|durI|j�	|�q!|j�	|�q!||_|S)a� The 'case' statements in a 'switch' come out of parsing with one
 5          child node, so subsequent statements are just tucked to the parent
 6          Compound. Additionally, consecutive (fall-through) case statements
 7          come out messy. This is a peculiarity of the C grammar. The following:
 8  
 9              switch (myvar) {
10                  case 10:
11                      k = 10;
12                      p = k + 1;
13                      return 10;
14                  case 20:
15                  case 30:
16                      return 20;
17                  default:
18                      break;
19              }
20  
21          Creates this tree (pseudo-dump):
22  
23              Switch
24                  ID: myvar
25                  Compound:
26                      Case 10:
27                          k = 10
28                      p = k + 1
29                      return 10
30                      Case 20:
31                          Case 30:
32                              return 20
33                      Default:
34                          break
35  
36          The goal of this transform is to fix this mess, turning it into the
37          following:
38  
39              Switch
40                  ID: myvar
41                  Compound:
42                      Case 10:
43                          k = 10
44                          p = k + 1
45                          return 10
46                      Case 20:
47                      Case 30:
48                          return 20
49                      Default:
50                          break
51  
52          A fixed AST node is returned. The argument may be modified.
53      N�����)�
54  isinstancer�Switch�stmt�Compound�coord�block_items�Case�Default�append�_extract_nested_case�stmts)Zswitch_nodeZnew_compoundZ	last_case�child�r��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pycparser\ast_transforms.py�fix_switch_cases
s3rcCs>t|jdtjtjf�r|�|j���t|d|�dSdS)z� Recursively extract consecutive Case statements that are made nested
55          by the parser and add them to the stmts_list.
56      �rN)rrrr
57  rr�popr
)Z	case_nodeZ
58  stmts_listrrrr
cs�r
cCs�	t|�\}}|s
59  nq|}t|tj�s*z|j}Wnty#|YSwt|tj�rd|jvr:d|jvr:|j�d�|jdurC|j	|_|S)aK Atomic specifiers like _Atomic(type) are unusually structured,
60          conferring a qualifier upon the contained type.
61  
62          This function fixes a decl with atomic specifiers to have a sane AST
63          structure, by removing spurious Typename->TypeDecl pairs and attaching
64          the _Atomic qualifier in the right place.
65      T�_AtomicN)
66  �_fix_atomic_specifiers_oncerr�TypeDecl�type�AttributeError�qualsr�declname�name)�decl�found�typrrr�fix_atomic_specifiersls$
67  �
68  ��
69  r cCs�|}d}|j}|dur2t|tj�rd|jvrnz	|}|}|j}Wn
ty-|dfYSw|dust|tj�s:J�|j|_d|jjvrK|jj�d�|dfS)z� Performs one 'fix' round of atomic specifiers.
70          Returns (modified_decl, found) where found is True iff a fix was made.
71      NrFT)rrr�Typenamerrrr)r�parentZgrandparent�noderrrr�s&
72  ��
rN)�rrr
r rrrrr�<module>s
73  	V