xsubs/compound.xs

filter: Statementstmt 100% 92 / 92 Branchbran 84.0% 79 / 94 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 91.9% 171 / 186 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xsubs/def.xs ↑ Summary xsubs/enum.xs »
1 ################################################################################
2 #
3 # Copyright (c) 2002-2020 Marcus Holland-Moritz. All rights reserved.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the same terms as Perl itself.
6 #
7 ################################################################################
8  
9  
10 ################################################################################
11 #
12 # METHOD: compound_names / struct_names / union_names
13 #
14 # WRITTEN BY: Marcus Holland-Moritz ON: Aug 2002
15 # CHANGED BY: ON:
16 #
17 ################################################################################
18  
19 void
20 CBC::compound_names()
21 ALIAS:
22 struct_names = 1
23 union_names = 2
24  
25 PREINIT:
26 7917 CBC_METHOD_VAR;
27 ListIterator li;
28 Struct *pStruct;
29 7917 int count = 0;
30 U32 context;
31 u_32 mask;
32  
33 PPCODE:
34 7917 switch (ix)
35 {
36 59 case 1: /* struct_names */
37 59 CBC_METHOD_SET("struct_names");
38 59 mask = T_STRUCT;
39 59 break;
40 57 case 2: /* union_names */
41 57 CBC_METHOD_SET("union_names");
42 57 mask = T_UNION;
43 57 break;
44 7801 default: /* compound_names */
45 7801 CBC_METHOD_SET("compound_names");
46 7801 mask = T_STRUCT | T_UNION;
47 7801 break;
48 }
49  
50 CT_DEBUG_METHOD;
51  
52 7917 ▶ CHECK_PARSE_DATA;
Branch: 1 branch
BranchTrueFalseTotal
CHECK_PARSE_DATA; 18 7899 7917
53 7899 ▶ CHECK_VOID_CONTEXT;
Branch: 2 branches
BranchTrueFalseTotal
CHECK_VOID_CONTEXT; 18 7881 7899
CHECK_VOID_CONTEXT; 12 6 18
54  
55 7881 context = GIMME_V;
56  
57 17150 ▶ LL_foreach(pStruct, li, THIS->cpi.structs)
Branch: 2 branches
BranchTrueFalseTotal
LL_foreach(pStruct, li, THIS->cpi.structs) 9269 7881 17150
LL_foreach(pStruct, li, THIS->cpi.structs) 9269 7881 17150
58 9269 ▶ if (pStruct->identifier[0] &&
Branch: 1 branch
BranchTrueFalseTotal
if (pStruct->identifier[0] && 8923 346 9269
59 8923 ▶ pStruct->declarations &&
Branch: 1 branch
BranchTrueFalseTotal
pStruct->declarations && 8923 0 8923
60 8923 ▶ pStruct->tflags & mask)
Branch: 1 branch
BranchTrueFalseTotal
pStruct->tflags & mask) 8550 373 8923
61 {
62 8550 ▶ if (context == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (context == G_ARRAY) 5690 2860 8550
63 5690 ▶ XPUSHs(sv_2mortal(newSVpv(pStruct->identifier, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(pStruct->identifier, 0))); 0 5690 5690
64 8550 count++;
65 }
66  
67 7881 ▶ if (context == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (context == G_ARRAY) 5280 2601 7881
68 5280 XSRETURN(count);
69 else
70 2601 XSRETURN_IV(count);
71  
72  
73 ################################################################################
74 #
75 # METHOD: compound / struct / union
76 #
77 # WRITTEN BY: Marcus Holland-Moritz ON: Aug 2002
78 # CHANGED BY: ON:
79 #
80 ################################################################################
81  
82 void
83 CBC::compound(...)
84 ALIAS:
85 struct = 1
86 union = 2
87  
88 PREINIT:
89 555 CBC_METHOD_VAR;
90 Struct *pStruct;
91 U32 context;
92 u_32 mask;
93  
94 PPCODE:
95 555 switch(ix)
96 {
97 222 case 1: /* struct */
98 222 CBC_METHOD_SET("struct");
99 222 mask = T_STRUCT;
100 222 break;
101 92 case 2: /* union */
102 92 CBC_METHOD_SET("union");
103 92 mask = T_UNION;
104 92 break;
105 241 default: /* compound */
106 241 CBC_METHOD_SET("compound");
107 241 mask = T_STRUCT | T_UNION;
108 241 break;
109 }
110  
111 CT_DEBUG_METHOD;
112  
113 555 ▶ CHECK_PARSE_DATA;
Branch: 1 branch
BranchTrueFalseTotal
CHECK_PARSE_DATA; 20 535 555
114 535 ▶ CHECK_VOID_CONTEXT;
Branch: 2 branches
BranchTrueFalseTotal
CHECK_VOID_CONTEXT; 18 517 535
CHECK_VOID_CONTEXT; 12 6 18
115  
116 517 context = GIMME_V;
117  
118 517 ▶ if (context == G_SCALAR && items != 2)
Branch: 2 branches
BranchTrueFalseTotal
if (context == G_SCALAR && items != 2) 156 361 517
if (context == G_SCALAR && items != 2) 23 133 156
119 {
120 23 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 2 21 23
121 2 XSRETURN_IV(items-1);
122 21 ▶ else if (mask == (T_STRUCT|T_UNION))
Branch: 1 branch
BranchTrueFalseTotal
else if (mask == (T_STRUCT|T_UNION)) 7 14 21
123 7 XSRETURN_IV(LL_count(THIS->cpi.structs));
124 else
125 {
126 ListIterator li;
127 14 int count = 0;
128  
129 378 ▶ LL_foreach(pStruct, li, THIS->cpi.structs)
Branch: 2 branches
BranchTrueFalseTotal
LL_foreach(pStruct, li, THIS->cpi.structs) 364 14 378
LL_foreach(pStruct, li, THIS->cpi.structs) 364 14 378
130 364 ▶ if (pStruct->tflags & mask)
Branch: 1 branch
BranchTrueFalseTotal
if (pStruct->tflags & mask) 182 182 364
131 182 count++;
132  
133 14 XSRETURN_IV(count);
134 }
135 }
136  
137 494 ▶ NEED_PARSE_DATA;
Branch: 2 branches
BranchTrueFalseTotal
NEED_PARSE_DATA; 494 0 494
NEED_PARSE_DATA; 30 464 494
138  
139 494 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 397 97 494
140 {
141 int i;
142  
143 844 ▶ for (i = 1; i < items; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i++) 447 397 844
144 {
145 const char *name;
146 447 u_32 limit = mask;
147  
148 447 name = SvPV_nolen(ST(i));
149  
150 /* skip optional union/struct */
151 447 ▶ if(mask & T_UNION &&
Branch: 1 branch
BranchTrueFalseTotal
if(mask & T_UNION && 258 189 447
152 258 ▶ name[0] == 'u' &&
Branch: 1 branch
BranchTrueFalseTotal
name[0] == 'u' && 34 224 258
153 34 ▶ name[1] == 'n' &&
Branch: 1 branch
BranchTrueFalseTotal
name[1] == 'n' && 34 0 34
154 34 ▶ name[2] == 'i' &&
Branch: 1 branch
BranchTrueFalseTotal
name[2] == 'i' && 34 0 34
155 34 ▶ name[3] == 'o' &&
Branch: 1 branch
BranchTrueFalseTotal
name[3] == 'o' && 34 0 34
156 34 ▶ name[4] == 'n' &&
Branch: 1 branch
BranchTrueFalseTotal
name[4] == 'n' && 34 0 34
157 34 ▶ isSPACE(name[5]))
Branch: 1 branch
BranchTrueFalseTotal
isSPACE(name[5])) 34 0 34
158 {
159 34 name += 6;
160 34 limit = T_UNION;
161 }
162 else
163 413 ▶ if(mask & T_STRUCT &&
Branch: 1 branch
BranchTrueFalseTotal
if(mask & T_STRUCT && 383 30 413
164 383 ▶ name[0] == 's' &&
Branch: 1 branch
BranchTrueFalseTotal
name[0] == 's' && 41 342 383
165 41 ▶ name[1] == 't' &&
Branch: 1 branch
BranchTrueFalseTotal
name[1] == 't' && 41 0 41
166 41 ▶ name[2] == 'r' &&
Branch: 1 branch
BranchTrueFalseTotal
name[2] == 'r' && 41 0 41
167 41 ▶ name[3] == 'u' &&
Branch: 1 branch
BranchTrueFalseTotal
name[3] == 'u' && 41 0 41
168 41 ▶ name[4] == 'c' &&
Branch: 1 branch
BranchTrueFalseTotal
name[4] == 'c' && 41 0 41
169 41 ▶ name[5] == 't' &&
Branch: 1 branch
BranchTrueFalseTotal
name[5] == 't' && 41 0 41
170 41 ▶ isSPACE(name[6]))
Branch: 1 branch
BranchTrueFalseTotal
isSPACE(name[6])) 41 0 41
171 {
172 41 name += 7;
173 41 limit = T_STRUCT;
174 }
175  
176 462 ▶ while (isSPACE(*name))
Branch: 1 branch
BranchTrueFalseTotal
while (isSPACE(*name)) 15 447 462
177 15 name++;
178  
179 447 pStruct = HT_get(THIS->cpi.htStructs, name, 0, 0);
180  
181 447 ▶ if (pStruct && pStruct->tflags & limit)
Branch: 2 branches
BranchTrueFalseTotal
if (pStruct && pStruct->tflags & limit) 384 63 447
if (pStruct && pStruct->tflags & limit) 360 24 384
182 360 PUSHs(sv_2mortal(get_struct_spec_def(aTHX_ &THIS->cfg, pStruct)));
183 else
184 87 PUSHs(&PL_sv_undef);
185 }
186  
187 397 XSRETURN(items-1);
188 }
189 else
190 {
191 ListIterator li;
192 97 int count = 0;
193  
194 603 ▶ LL_foreach(pStruct, li, THIS->cpi.structs)
Branch: 2 branches
BranchTrueFalseTotal
LL_foreach(pStruct, li, THIS->cpi.structs) 409 97 506
LL_foreach(pStruct, li, THIS->cpi.structs) 409 97 506
195 409 ▶ if (pStruct->tflags & mask)
Branch: 1 branch
BranchTrueFalseTotal
if (pStruct->tflags & mask) 273 136 409
196 {
197 273 ▶ XPUSHs(sv_2mortal(get_struct_spec_def(aTHX_ &THIS->cfg, pStruct)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(get_struct_spec_def(aTHX_ &THIS->cfg, pStruct))); 0 273 273
198 273 count++;
199 }
200  
201 97 XSRETURN(count);
202 }
203  
« xsubs/def.xs ↑ Summary xsubs/enum.xs »