epcomp.c

filter: Statementstmt 0.0% 0 / 896 Branchbran 0.0% 0 / 746 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 1642 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« epcmd2.c ↑ Summary epdefault.c »
1 /*###################################################################################
2 #
3 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
4 # Embperl - Copyright (c) 2008-2015 Gerald Richter
5 # Embperl - Copyright (c) 2015-2023 actevy.io
6 #
7 # You may distribute under the terms of either the GNU General Public
8 # License or the Artistic License, as specified in the Perl README file.
9 #
10 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 #
14 ###################################################################################*/
15  
16  
17 #include "ep.h"
18 #include "epmacro.h"
19  
20 struct tEmbperlCmd
21 {
22 int bValid ;
23 const char * * sPerlCode ; /* perl code that should be inserted (maybe an array) */
24 const char * * sCompileTimePerlCode ; /* perl code that should be directly executed (maybe an array) */
25 const char * sCompileTimePerlCodeEnd ; /* perl code that should be directly executed at the end tag */
26 const char * sPerlCodeEnd ; /* perl code that should be inserted at the end tag */
27 const char * sStackName ;
28 const char * sPushStack ;
29 const char * sPopStack ;
30 const char * sMatchStack ;
31 const char * sStackName2 ;
32 const char * sPushStack2 ;
33 const char * sPopStack2 ;
34 int numPerlCode ;
35 int numCompileTimePerlCode ;
36 int bRemoveNode ;
37 int bPerlCodeRemove ;
38 int bCompileChilds ;
39 int nNodeType ;
40 int nSwitchCodeType ;
41 int bCallReturn ;
42 const char * sMayJump ;
43 struct tEmbperlCmd * pNext ;
44 } ;
45  
46 typedef struct tEmbperlCmd tEmbperlCmd ;
47  
48  
49 struct tEmbperlCompilerInfo
50 {
51 tStringIndex nMaxEmbperlCmd ;
52 tEmbperlCmd * pEmbperlCmds ;
53 } ;
54  
55 typedef struct tEmbperlCompilerInfo tEmbperlCompilerInfo ;
56  
57 /* ------------------------------------------------------------------------ */
58 /* */
59 /* embperl_CompileInit */
60 /* */
61 /* */
62 /* */
63 /* ------------------------------------------------------------------------ */
64  
65  
66 0 static int embperl_CompileInit (/*in*/ tApp * a,
67 /*out*/ tEmbperlCompilerInfo * * ppInfo)
68  
69 {
70 epaTHX_
71 0 tEmbperlCompilerInfo * pInfo = malloc (sizeof (tEmbperlCompilerInfo)) ;
72  
73 0 ▶ if (!pInfo)
Branch: 1 branch
BranchTrueFalseTotal
if (!pInfo) 0 0 0
74 0 return rcOutOfMemory ;
75  
76  
77  
78 0 ArrayNewZero (a, &pInfo -> pEmbperlCmds, 256, sizeof (struct tEmbperlCmd)) ;
79 0 ArraySet (a, &pInfo -> pEmbperlCmds, 0) ;
80 0 pInfo -> nMaxEmbperlCmd = 1 ;
81 0 *ppInfo = pInfo ;
82  
83 0 return ok ;
84 }
85  
86  
87 /* ------------------------------------------------------------------------ */
88 /* */
89 /* embperl_CompileInitItem */
90 /* */
91 /* */
92 /* */
93 /* ------------------------------------------------------------------------ */
94  
95 0 int embperl_CompileInitItem (/*i/o*/ register req * r,
96 /*in*/ HV * pHash,
97 /*in*/ int nNodeName,
98 /*in*/ int nNodeType,
99 /*in*/ int nTagSet,
100 /*in*/ void * * ppInfo)
101  
102 {
103 epTHX_
104 SV * * ppSV ;
105 AV * pAV ;
106 tEmbperlCmd * pCmd ;
107 0 tEmbperlCompilerInfo * pInfo = (tEmbperlCompilerInfo *)*ppInfo ;
108  
109 0 ▶ if (!pInfo)
Branch: 1 branch
BranchTrueFalseTotal
if (!pInfo) 0 0 0
110 0 embperl_CompileInit (r -> pApp, (tEmbperlCompilerInfo * *)ppInfo) ;
111 0 pInfo = (tEmbperlCompilerInfo *)*ppInfo ;
112
113  
114  
115 0 ArraySet (r -> pApp, &pInfo -> pEmbperlCmds, nNodeName+1) ;
116  
117 0 ▶ if (pInfo -> nMaxEmbperlCmd < nNodeName)
Branch: 1 branch
BranchTrueFalseTotal
if (pInfo -> nMaxEmbperlCmd < nNodeName) 0 0 0
118 0 pInfo -> nMaxEmbperlCmd = nNodeName ;
119 0 pCmd = &pInfo -> pEmbperlCmds[nNodeName] ;
120  
121 0 ▶ if (pCmd -> bValid)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> bValid) 0 0 0
122 {
123 tEmbperlCmd * pNewCmd ;
124 0 ▶ if (pCmd -> bValid == nTagSet)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> bValid == nTagSet) 0 0 0
125 0 return ok ;
126
127 0 ▶ while (pCmd -> pNext)
Branch: 1 branch
BranchTrueFalseTotal
while (pCmd -> pNext) 0 0 0
128 {
129 0 ▶ if (pCmd -> bValid == nTagSet)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> bValid == nTagSet) 0 0 0
130 0 return ok ;
131 0 pCmd = pCmd -> pNext ;
132 }
133  
134 0 ▶ if (pCmd -> bValid == nTagSet)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> bValid == nTagSet) 0 0 0
135 0 return ok ;
136  
137 0 pNewCmd = malloc (sizeof (*pNewCmd)) ;
138 0 pCmd -> pNext = pNewCmd ;
139 0 pCmd = pNewCmd ;
140 0 memset (pCmd, 0, sizeof(*pCmd)) ;
141 }
142 0 pCmd -> bValid = nTagSet ;
143  
144 0 ppSV = hv_fetch(pHash, "perlcode", 8, 0) ;
145 0 ▶ if (ppSV != NULL && *ppSV != NULL &&
Branch: 2 branches
BranchTrueFalseTotal
if (ppSV != NULL && *ppSV != NULL && 0 0 0
if (ppSV != NULL && *ppSV != NULL && 0 0 0
146 0 ▶ SvROK(*ppSV) && SvTYPE((pAV = (AV *)SvRV(*ppSV))) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
SvROK(*ppSV) && SvTYPE((pAV = (AV *)SvRV(*ppSV))) == SVt_PVAV) 0 0 0
SvROK(*ppSV) && SvTYPE((pAV = (AV *)SvRV(*ppSV))) == SVt_PVAV) 0 0 0
147 0 { /* Array reference */
148 0 int f = AvFILL(pAV) + 1 ;
149 int i ;
150 STRLEN l ;
151  
152 0 pCmd -> sPerlCode = malloc (f * sizeof (char *)) ;
153 0 pCmd -> numPerlCode = f ;
154  
155 0 ▶ for (i = 0; i < f; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < f; i++) 0 0 0
156 {
157 0 ppSV = av_fetch (pAV, i, 0) ;
158 0 ▶ if (ppSV && *ppSV)
Branch: 2 branches
BranchTrueFalseTotal
if (ppSV && *ppSV) 0 0 0
if (ppSV && *ppSV) 0 0 0
159 0 pCmd -> sPerlCode[i] = strdup (SvPV (*ppSV, l)) ;
160 else
161 0 pCmd -> sPerlCode[i] = NULL ;
162 }
163 }
164 else
165 {
166 0 ▶ if (ppSV)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV) 0 0 0
167 {
168 STRLEN l ;
169
170 0 pCmd -> sPerlCode = malloc (sizeof (char *)) ;
171 0 pCmd -> numPerlCode = 1 ;
172 0 pCmd -> sPerlCode[0] = sstrdup (r, SvPV (*ppSV, l)) ;
173 }
174 }
175
176  
177 0 ppSV = hv_fetch(pHash, "compiletimeperlcode", 19, 0) ;
178 0 ▶ if (ppSV != NULL && *ppSV != NULL &&
Branch: 2 branches
BranchTrueFalseTotal
if (ppSV != NULL && *ppSV != NULL && 0 0 0
if (ppSV != NULL && *ppSV != NULL && 0 0 0
179 0 ▶ SvROK(*ppSV) && SvTYPE((pAV = (AV *)SvRV(*ppSV))) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
SvROK(*ppSV) && SvTYPE((pAV = (AV *)SvRV(*ppSV))) == SVt_PVAV) 0 0 0
SvROK(*ppSV) && SvTYPE((pAV = (AV *)SvRV(*ppSV))) == SVt_PVAV) 0 0 0
180 0 { /* Array reference */
181 0 int f = AvFILL(pAV) + 1 ;
182 int i ;
183 STRLEN l ;
184  
185 0 pCmd -> sCompileTimePerlCode = malloc (f * sizeof (char *)) ;
186 0 pCmd -> numCompileTimePerlCode = f ;
187  
188 0 ▶ for (i = 0; i < f; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < f; i++) 0 0 0
189 {
190 0 ppSV = av_fetch (pAV, i, 0) ;
191 0 ▶ if (ppSV && *ppSV)
Branch: 2 branches
BranchTrueFalseTotal
if (ppSV && *ppSV) 0 0 0
if (ppSV && *ppSV) 0 0 0
192 0 pCmd -> sCompileTimePerlCode[i] = strdup (SvPV (*ppSV, l)) ;
193 else
194 0 pCmd -> sCompileTimePerlCode[i] = NULL ;
195 }
196 }
197 else
198 {
199 0 ▶ if (ppSV)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV) 0 0 0
200 {
201 STRLEN l ;
202
203 0 pCmd -> sCompileTimePerlCode = malloc (sizeof (char *)) ;
204 0 pCmd -> numCompileTimePerlCode = 1 ;
205 0 pCmd -> sCompileTimePerlCode[0] = sstrdup (r, SvPV (*ppSV, l)) ;
206 }
207 }
208
209
210
211
212 0 pCmd -> sPerlCodeEnd = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "perlcodeend", NULL) ;
213 0 pCmd -> sCompileTimePerlCodeEnd = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "compiletimeperlcodeend", NULL) ;
214 0 pCmd -> sStackName = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "stackname", NULL) ;
215 0 pCmd -> sPushStack = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "push", NULL) ;
216 0 pCmd -> sPopStack = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "pop", NULL) ;
217 0 pCmd -> sMatchStack = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "stackmatch", NULL) ;
218 0 pCmd -> sStackName2 = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "stackname2", NULL) ;
219 0 pCmd -> sPushStack2 = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "push2", NULL) ;
220 0 pCmd -> sPopStack2 = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "pop2", NULL) ;
221 0 pCmd -> bRemoveNode = GetHashValueInt (aTHX_ pHash, "removenode", 0) ;
222 0 pCmd -> sMayJump = GetHashValueStrDup (aTHX_ r -> pThread -> pMainPool, pHash, "mayjump", NULL) ;
223 0 pCmd -> bPerlCodeRemove = GetHashValueInt (aTHX_ pHash, "perlcoderemove", 0) ;
224 0 pCmd -> bCompileChilds = GetHashValueInt (aTHX_ pHash, "compilechilds", 1) ;
225 0 pCmd -> nSwitchCodeType = GetHashValueInt (aTHX_ pHash, "switchcodetype", 0) ;
226 0 pCmd -> bCallReturn = GetHashValueInt (aTHX_ pHash, "callreturn", 0) ;
227 0 ▶ pCmd -> nNodeType = nNodeType == ntypStartEndTag?ntypStartTag:nNodeType ;
Branch: 1 branch
BranchTrueFalseTotal
pCmd -> nNodeType = nNodeType == ntypStartEndTag?ntypStartTag:nNodeType ; 0 0 0
228 0 pCmd -> pNext = NULL ;
229  
230 0 pInfo -> pEmbperlCmds[nNodeName].bRemoveNode |= pCmd -> bRemoveNode ;
231 /* pInfo -> pEmbperlCmds[nNodeName].bPerlCodeRemove |= pCmd -> bPerlCodeRemove ; */
232 0 ▶ if (pCmd -> nSwitchCodeType)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> nSwitchCodeType) 0 0 0
233 0 pInfo -> pEmbperlCmds[nNodeName].nSwitchCodeType = pCmd -> nSwitchCodeType ;
234 0 ▶ if (pCmd -> sMayJump && !pInfo -> pEmbperlCmds[nNodeName].sMayJump)
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd -> sMayJump && !pInfo -> pEmbperlCmds[nNodeName].sMayJump) 0 0 0
if (pCmd -> sMayJump && !pInfo -> pEmbperlCmds[nNodeName].sMayJump) 0 0 0
235 0 pInfo -> pEmbperlCmds[nNodeName].sMayJump = pCmd -> sMayJump ;
236  
237 0 ▶ if (r -> Component.Config.bDebug & dbgBuildToken)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgBuildToken) 0 0 0
238 0 lprintf (r -> pApp, "[%d]EPCOMP: InitItem %s (#%d) perlcode=%s (num=%d) perlcodeend=%s compilechilds=%d removenode=%d nodetype=%d\n",
239 0 r -> pThread -> nPid, Ndx2String(nNodeName), nNodeName,
240 0 ▶ pCmd -> sPerlCode?pCmd -> sPerlCode[0]:"",
Branch: 1 branch
BranchTrueFalseTotal
pCmd -> sPerlCode?pCmd -> sPerlCode[0]:"", 0 0 0
241 pCmd -> numPerlCode,
242 0 ▶ pCmd -> sPerlCodeEnd?pCmd -> sPerlCodeEnd:"<undef>",
Branch: 1 branch
BranchTrueFalseTotal
pCmd -> sPerlCodeEnd?pCmd -> sPerlCodeEnd:"<undef>", 0 0 0
243 pCmd -> bCompileChilds,
244 pCmd -> bRemoveNode,
245 pCmd -> nNodeType) ;
246  
247 0 return ok ;
248 }
249  
250 /* ------------------------------------------------------------------------ */
251 /* */
252 /* strstrn */
253 /* */
254 /* find substring of length n */
255 /* */
256 /* ------------------------------------------------------------------------ */
257  
258 0 static const char * strstrn (const char * s1, const char * s2, int l)
259  
260 {
261 0 ▶ while (*s1)
Branch: 1 branch
BranchTrueFalseTotal
while (*s1) 0 0 0
262 {
263 0 ▶ if ((s1 = strchr (s1, *s2)) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if ((s1 = strchr (s1, *s2)) == NULL) 0 0 0
264 0 return NULL ;
265 0 ▶ if (strncmp (s1, s2, l) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strncmp (s1, s2, l) == 0) 0 0 0
266 0 return s1 ;
267 0 s1++ ;
268 }
269  
270 0 return NULL ;
271 }
272  
273  
274 /* ------------------------------------------------------------------------ */
275 /* */
276 /* embperl_CompileAddValue */
277 /* */
278 /* Add value to perl code */
279 /* */
280 /* ------------------------------------------------------------------------ */
281  
282  
283 0 static int embperl_CompileAddValue (/*in*/ tReq * r,
284 /*in*/ const char * sText,
285 const char * p,
286 const char * q,
287 const char * eq,
288 char op,
289 char out,
290 /*i/o*/ char * * ppCode )
291  
292  
293  
294  
295 {
296 const char * or ;
297 const char * e ;
298  
299
300 0 ▶ if (sText)
Branch: 1 branch
BranchTrueFalseTotal
if (sText) 0 0 0
301 {
302 0 int l = strlen (sText) ;
303 0 ▶ if (out == 3)
Branch: 1 branch
BranchTrueFalseTotal
if (out == 3) 0 0 0
304 {
305 0 out = 2 ;
306 0 ▶ while (isspace (*sText))
Branch: 1 branch
BranchTrueFalseTotal
while (isspace (*sText)) 0 0 0
307 0 sText++, l-- ;
308 0 ▶ while (l > 0 && isspace (sText[l-1]))
Branch: 2 branches
BranchTrueFalseTotal
while (l > 0 && isspace (sText[l-1])) 0 0 0
while (l > 0 && isspace (sText[l-1])) 0 0 0
309 0 l-- ;
310 }
311  
312 0 ▶ if (op == '=' && eq)
Branch: 2 branches
BranchTrueFalseTotal
if (op == '=' && eq) 0 0 0
if (op == '=' && eq) 0 0 0
313 {
314 0 eq++ ;
315 do
316 {
317 0 or = strchr (eq + 1, '|') ;
318 0 ▶ e = or?or:q ;
Branch: 1 branch
BranchTrueFalseTotal
e = or?or:q ; 0 0 0
319 0 ▶ if (strnicmp (sText, eq, e - eq) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strnicmp (sText, eq, e - eq) == 0) 0 0 0
320 0 break ;
321 0 ▶ if (or == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (or == NULL) 0 0 0
322 0 return 0 ;
323 0 eq = or + 1 ;
324 }
325 0 ▶ while (or) ;
Branch: 1 branch
BranchTrueFalseTotal
while (or) ; 0 0 0
326 }
327 0 ▶ else if (op == '~' && eq)
Branch: 2 branches
BranchTrueFalseTotal
else if (op == '~' && eq) 0 0 0
else if (op == '~' && eq) 0 0 0
328 {
329 0 eq++ ;
330 do
331 {
332 char * f ;
333
334 0 or = strchr (eq + 1, '|') ;
335 0 ▶ e = or?or:q ;
Branch: 1 branch
BranchTrueFalseTotal
e = or?or:q ; 0 0 0
336 0 ▶ if ((f = (char *)strstrn (sText, eq, e - eq)))
Branch: 1 branch
BranchTrueFalseTotal
if ((f = (char *)strstrn (sText, eq, e - eq))) 0 0 0
337 0 ▶ if (!isalnum (f[e - eq]) && f[e - eq] != '_')
Branch: 2 branches
BranchTrueFalseTotal
if (!isalnum (f[e - eq]) && f[e - eq] != '_') 0 0 0
if (!isalnum (f[e - eq]) && f[e - eq] != '_') 0 0 0
338 0 break ;
339 0 ▶ if (or == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (or == NULL) 0 0 0
340 0 return 0 ;
341 0 eq = or + 1 ;
342 }
343 0 ▶ while (or) ;
Branch: 1 branch
BranchTrueFalseTotal
while (or) ; 0 0 0
344 }
345 0 ▶ else if (op == '!' && sText)
Branch: 2 branches
BranchTrueFalseTotal
else if (op == '!' && sText) 0 0 0
else if (op == '!' && sText) 0 0 0
346 {
347 0 return 0 ;
348 }
349  
350 0 ▶ if (out)
Branch: 1 branch
BranchTrueFalseTotal
if (out) 0 0 0
351 {
352 0 ▶ if (out == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (out == 2) 0 0 0
353 {
354 0 const char * s = sText ;
355  
356 0 StringAdd (r -> pApp, ppCode, "'", 1) ;
357 0 ▶ while (*s && l--)
Branch: 2 branches
BranchTrueFalseTotal
while (*s && l--) 0 0 0
while (*s && l--) 0 0 0
358 {
359 0 ▶ if (*s == '\'')
Branch: 1 branch
BranchTrueFalseTotal
if (*s == '\'') 0 0 0
360 {
361 0 ▶ if (sText < s)
Branch: 1 branch
BranchTrueFalseTotal
if (sText < s) 0 0 0
362 0 StringAdd (r -> pApp, ppCode, sText, s - sText) ;
363 0 StringAdd (r -> pApp, ppCode, "\\'", 2) ;
364 0 sText = s + 1 ;
365 }
366 0 ▶ else if (*s == '\\')
Branch: 1 branch
BranchTrueFalseTotal
else if (*s == '\\') 0 0 0
367 {
368 0 ▶ if (sText < s)
Branch: 1 branch
BranchTrueFalseTotal
if (sText < s) 0 0 0
369 0 StringAdd (r -> pApp, ppCode, sText, s - sText) ;
370 0 StringAdd (r -> pApp, ppCode, "\\\\", 2) ;
371 0 sText = s + 1 ;
372 }
373 0 s++ ;
374 }
375 0 ▶ if (sText < s)
Branch: 1 branch
BranchTrueFalseTotal
if (sText < s) 0 0 0
376 0 StringAdd (r -> pApp, ppCode, sText, s - sText) ;
377 0 StringAdd (r -> pApp, ppCode, "'", 1) ;
378 }
379 0 ▶ else if (out)
Branch: 1 branch
BranchTrueFalseTotal
else if (out) 0 0 0
380 0 StringAdd (r -> pApp, ppCode, sText, 0) ;
381 }
382 }
383 else
384 {
385 0 ▶ if (op != '!' && op != 0)
Branch: 2 branches
BranchTrueFalseTotal
if (op != '!' && op != 0) 0 0 0
if (op != '!' && op != 0) 0 0 0
386 0 return 0 ;
387
388 /*
389 if (out == 2)
390 StringAdd (r -> pApp, ppCode, "''", 2) ;
391 0 ▶ else */ if (out)
Branch: 1 branch
BranchTrueFalseTotal
else */ if (out) 0 0 0
392 0 StringAdd (r -> pApp, ppCode, "undef", 5) ;
393 }
394  
395 0 return 1 ;
396 }
397  
398  
399 /* ------------------------------------------------------------------------ */
400 /* */
401 /* embperl_CompilePushStack */
402 /* */
403 /* Push valuie on named stack */
404 /* */
405 /* ------------------------------------------------------------------------ */
406  
407  
408 0 static void embperl_CompilePushStack (/*in*/ tReq * r,
409 /*in*/ tDomTree * pDomTree,
410 const char * sStackName,
411 const char * sStackValue)
412
413 {
414 epTHX_
415 SV ** ppSV ;
416 SV * pSV ;
417 AV * pAV ;
418  
419 0 ppSV = hv_fetch((HV *)(pDomTree -> pSV), (char *)sStackName, strlen (sStackName), 1) ;
420 0 ▶ if (ppSV == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV == NULL) 0 0 0
421 0 return ;
422  
423 0 ▶ if (*ppSV == NULL || !SvROK (*ppSV))
Branch: 2 branches
BranchTrueFalseTotal
if (*ppSV == NULL || !SvROK (*ppSV)) 0 0 0
if (*ppSV == NULL || !SvROK (*ppSV)) 0 0 0
424 {
425 0 ▶ if (*ppSV)
Branch: 1 branch
BranchTrueFalseTotal
if (*ppSV) 0 0 0
426 0 SvREFCNT_dec (*ppSV) ;
427 0 *ppSV = newRV_noinc ((SV *)(pAV = newAV ())) ;
428 }
429 else
430 0 pAV = (AV *)SvRV (*ppSV) ;
431
432
433 0 pSV = newSVpv ((char *)sStackValue, strlen (sStackValue)) ;
434 0 ▶ SvUPGRADE (pSV, SVt_PVIV) ;
Branch: 1 branch
BranchTrueFalseTotal
SvUPGRADE (pSV, SVt_PVIV) ; 0 0 0
435 0 SvIVX (pSV) = 0 ;
436 0 av_push (pAV, pSV) ;
437 }
438  
439  
440 /* ------------------------------------------------------------------------ */
441 /* */
442 /* embperl_CompilePopStack */
443 /* */
444 /* pop value from named stack */
445 /* */
446 /* ------------------------------------------------------------------------ */
447  
448  
449 0 static void embperl_CompilePopStack (/*in*/ tReq * r,
450 /*in*/ tDomTree * pDomTree,
451 const char * sStackName)
452
453 {
454 epTHX_
455 SV ** ppSV ;
456 SV * pSV ;
457  
458 0 ppSV = hv_fetch((HV *)(pDomTree -> pSV), (char *)sStackName, strlen (sStackName), 0) ;
459 0 ▶ if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV))
Branch: 3 branches
BranchTrueFalseTotal
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
460 0 return ;
461  
462 0 pSV = av_pop ((AV *)SvRV (*ppSV)) ;
463 0 SvREFCNT_dec (pSV) ;
464 }
465  
466 /* ------------------------------------------------------------------------ */
467 /* */
468 /* embperl_CompileMatchStack */
469 /* */
470 /* check if top of stack value matches given value */
471 /* */
472 /* ------------------------------------------------------------------------ */
473  
474  
475 0 static int embperl_CompileMatchStack (/*in*/ tReq * r,
476 /*in*/ tDomTree * pDomTree,
477 tNodeData * pNode,
478 const char * sStackName,
479 const char * sStackValue)
480
481 {
482 epTHX_
483 SV ** ppSV ;
484 SV * pSV ;
485 STRLEN l ;
486 char * s ;
487  
488 0 ppSV = hv_fetch((HV *)(pDomTree -> pSV), (char *)sStackName, strlen (sStackName), 0) ;
489 0 ▶ if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV))
Branch: 3 branches
BranchTrueFalseTotal
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
490 {
491 0 strcpy (r -> errdat1, "CompileMatchStack") ;
492 0 strncat (r -> errdat1, (char *)sStackName, sizeof (r -> errdat1) - 20) ;
493 0 return rcHashError ;
494 }
495
496 0 pSV = av_pop ((AV *)SvRV (*ppSV)) ;
497  
498 0 s = SvPV (pSV, l) ;
499 0 ▶ if (strcmp (s, sStackValue) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp (s, sStackValue) == 0) 0 0 0
500 {
501 0 SvREFCNT_dec (pSV) ;
502 0 return ok ;
503 }
504
505 0 strncpy (r -> errdat1, Node_selfNodeName (pNode), sizeof (r -> errdat1)) ;
506 0 sprintf (r -> errdat2, "'%s', starttag should be '%s' or there is a 'end%s' missing", s, sStackValue, s) ;
507 0 r -> Component.pCurrPos = NULL ;
508 0 r -> Component.nSourceline = pNode -> nLinenumber ;
509  
510 0 SvREFCNT_dec (pSV) ;
511  
512 0 return rcTagMismatch ;
513 }
514  
515  
516 /* ------------------------------------------------------------------------ */
517 /* */
518 /* embperl_CompileAddStack */
519 /* */
520 /* Add value of child node to perl code */
521 /* */
522 /* ------------------------------------------------------------------------ */
523  
524  
525 0 static int embperl_CompileAddStack (/*in*/ tReq * r,
526 /*in*/ tDomTree * pDomTree,
527 const char * p,
528 const char * q,
529 char op,
530 char out,
531 char str,
532 /*i/o*/ char * * ppCode )
533 {
534 epTHX_
535 0 const char * eq = strchr (p, ':') ;
536 0 ▶ const char * e = eq && eq < q?eq:q;
Branch: 2 branches
BranchTrueFalseTotal
const char * e = eq && eq < q?eq:q; 0 0 0
const char * e = eq && eq < q?eq:q; 0 0 0
537 STRLEN l ;
538 0 const char * sText = NULL ;
539 SV ** ppSV ;
540 AV * pAV ;
541  
542  
543 0 ppSV = hv_fetch((HV *)(pDomTree -> pSV), (char *)p, e - p, 0) ;
544 0 ▶ if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV))
Branch: 3 branches
BranchTrueFalseTotal
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
if (ppSV == NULL || *ppSV == NULL || !SvROK (*ppSV)) 0 0 0
545 0 return op == '!'?1:0 ;
546  
547 0 pAV = (AV *)SvRV (*ppSV) ;
548  
549 0 ▶ if (SvTYPE (pAV) != SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE (pAV) != SVt_PVAV) 0 0 0
550 0 return op == '!'?1:0 ;
551
552 0 ppSV = av_fetch (pAV, av_len (pAV), 0) ;
553 0 ▶ if (ppSV == NULL || *ppSV == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if (ppSV == NULL || *ppSV == NULL) 0 0 0
if (ppSV == NULL || *ppSV == NULL) 0 0 0
554 0 return op == '!'?1:0 ;
555  
556 0 ▶ if (str)
Branch: 1 branch
BranchTrueFalseTotal
if (str) 0 0 0
557 {
558 0 sText = SvPV (*ppSV, l) ;
559 0 (SvIVX (*ppSV))++ ;
560 }
561 else
562 0 ▶ sText = SvIVX (*ppSV)?"1":NULL ;
Branch: 1 branch
BranchTrueFalseTotal
sText = SvIVX (*ppSV)?"1":NULL ; 0 0 0
563  
564  
565 0 return embperl_CompileAddValue (r, sText, p, q, eq, op, out, ppCode) ;
566 }
567  
568 /* ------------------------------------------------------------------------ */
569 /* */
570 /* embperl_CompileAddChildNode */
571 /* */
572 /* Add value of child node to perl code */
573 /* */
574 /* ------------------------------------------------------------------------ */
575  
576  
577 0 static int embperl_CompileAddChildNode (/*in*/ tReq * r,
578 /*in*/ tDomTree * pDomTree,
579 /*in*/ tNodeData * pNode,
580 const char * p,
581 const char * q,
582 char op,
583 char out,
584 /*i/o*/ char * * ppCode )
585  
586  
587  
588 {
589 0 const char * eq = strchr (p, ':') ;
590 0 int nChildNo = atoi (p) ;
591 0 struct tNodeData * pChildNode = Node_selfNthChild (r -> pApp, pDomTree, pNode, 0, nChildNo) ;
592 0 const char * sText = NULL ;
593
594 0 ▶ if (pChildNode)
Branch: 1 branch
BranchTrueFalseTotal
if (pChildNode) 0 0 0
595 0 sText = Node_selfNodeName(pChildNode) ;
596  
597 0 return embperl_CompileAddValue (r, sText, p, q, eq, op, out, ppCode) ;
598 }
599  
600 /* ------------------------------------------------------------------------ */
601 /* */
602 /* embperl_CompileAddSiblingNode */
603 /* */
604 /* Add value of sibling node to perl code */
605 /* */
606 /* ------------------------------------------------------------------------ */
607  
608  
609 0 static int embperl_CompileAddSiblingNode (/*in*/ tReq * r,
610 /*in*/ tDomTree * pDomTree,
611 /*in*/ tNodeData * pNode,
612 const char * p,
613 const char * q,
614 char op,
615 char out,
616 /*i/o*/ char * * ppCode )
617  
618  
619  
620 {
621 0 const char * eq = strchr (p, ':') ;
622 0 int nChildNo = atoi (p) ;
623 struct tNodeData * pChildNode ;
624 0 const char * sText = NULL ;
625
626 0 ▶ if (nChildNo == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (nChildNo == 0) 0 0 0
627 0 pChildNode = pNode ;
628 0 ▶ else if (nChildNo > 0)
Branch: 1 branch
BranchTrueFalseTotal
else if (nChildNo > 0) 0 0 0
629 {
630 0 nChildNo-- ;
631 0 pChildNode = Node_selfNextSibling (r -> pApp, pDomTree, pNode, 0) ;
632 0 ▶ while (pChildNode && nChildNo-- > 0)
Branch: 2 branches
BranchTrueFalseTotal
while (pChildNode && nChildNo-- > 0) 0 0 0
while (pChildNode && nChildNo-- > 0) 0 0 0
633 0 pChildNode = Node_selfNextSibling (r -> pApp, pDomTree, pChildNode, 0) ;
634
635 }
636 else
637 {
638 0 nChildNo++ ;
639 0 pChildNode = Node_selfPreviousSibling (r -> pApp, pDomTree, pNode, 0) ;
640 0 ▶ while (pChildNode && nChildNo++ < 0)
Branch: 2 branches
BranchTrueFalseTotal
while (pChildNode && nChildNo++ < 0) 0 0 0
while (pChildNode && nChildNo++ < 0) 0 0 0
641 0 pChildNode = Node_selfPreviousSibling (r -> pApp, pDomTree, pChildNode, 0) ;
642
643 }
644
645 0 ▶ if (pChildNode)
Branch: 1 branch
BranchTrueFalseTotal
if (pChildNode) 0 0 0
646 0 sText = Node_selfNodeName(pChildNode) ;
647  
648 0 return embperl_CompileAddValue (r, sText, p, q, eq, op, out, ppCode) ;
649 }
650  
651 /* ------------------------------------------------------------------------ */
652 /* */
653 /* embperl_CompileAddAttribut */
654 /* */
655 /* Add value of child node to perl code */
656 /* */
657 /* ------------------------------------------------------------------------ */
658  
659  
660 0 static int embperl_CompileAddAttribut (/*in*/ tReq * r,
661 /*in*/ tDomTree * pDomTree,
662 /*in*/ tNodeData * pNode,
663 const char * p,
664 const char * q,
665 char op,
666 char out,
667 /*i/o*/ char * * ppCode )
668  
669  
670  
671 {
672 0 const char * eq = strchr (p, ':') ;
673 0 ▶ const char * e = eq && eq < q?eq:q;
Branch: 2 branches
BranchTrueFalseTotal
const char * e = eq && eq < q?eq:q; 0 0 0
const char * e = eq && eq < q?eq:q; 0 0 0
674 0 tAttrData * pChildNode = Element_selfGetAttribut (r -> pApp, pDomTree, pNode, p, e - p) ;
675 0 const char * sText = NULL ;
676 char buf [128] ;
677  
678
679 0 ▶ if (pChildNode)
Branch: 1 branch
BranchTrueFalseTotal
if (pChildNode) 0 0 0
680 {
681 0 ▶ if (pChildNode -> bFlags & aflgAttrChilds)
Branch: 1 branch
BranchTrueFalseTotal
if (pChildNode -> bFlags & aflgAttrChilds) 0 0 0
682 {
683 0 sprintf (buf, "XML::Embperl::DOM::Attr::iValue ($_ep_DomTree,%ld)", pChildNode -> xNdx) ;
684 0 sText = buf ;
685 0 ▶ if (out == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (out == 2) 0 0 0
686 0 out = 1 ;
687 }
688 else
689 {
690 0 sText = Ndx2String (pChildNode -> xValue) ;
691 }
692  
693 }
694
695 0 return embperl_CompileAddValue (r, sText, p, q, eq, op, out, ppCode) ;
696 }
697  
698 /* ------------------------------------------------------------------------ */
699 /* */
700 /* embperl_CompileToPerlCode */
701 /* */
702 /* Compile one command inside a node */
703 /* */
704 /* ------------------------------------------------------------------------ */
705  
706  
707 0 static int embperl_CompileToPerlCode (/*in*/ tReq * r,
708 /*in*/ tDomTree * pDomTree,
709 /*in*/ tNodeData * pNode,
710 /*in*/ const char * sPerlCode,
711 /*out*/ char * * ppCode )
712  
713  
714 {
715 const char * p ;
716 const char * q ;
717 0 int valid = 1 ;
718 0 tNode xCurrNode = 0 ;
719  
720 0 StringNew (r -> pApp, ppCode, 512) ;
721 0 ▶ if (sPerlCode)
Branch: 1 branch
BranchTrueFalseTotal
if (sPerlCode) 0 0 0
722 {
723 0 p = strchr (sPerlCode, '%') ;
724 0 ▶ while (p)
Branch: 1 branch
BranchTrueFalseTotal
while (p) 0 0 0
725 {
726 0 int n = p - sPerlCode ;
727 0 ▶ if (n)
Branch: 1 branch
BranchTrueFalseTotal
if (n) 0 0 0
728 0 StringAdd (r -> pApp, ppCode, sPerlCode, n) ;
729 0 q = strchr (p+1, '%') ;
730 0 ▶ if (q)
Branch: 1 branch
BranchTrueFalseTotal
if (q) 0 0 0
731 {
732 char type ;
733 char op ;
734 0 char out = 1 ;
735  
736 0 p++ ;
737 0 type = *p ;
738 0 p++ ;
739 0 op = *p ;
740 0 ▶ if (op != '=' && op != '*' && op != '!' && op != '~')
Branch: 4 branches
BranchTrueFalseTotal
if (op != '=' && op != '*' && op != '!' && op != '~') 0 0 0
if (op != '=' && op != '*' && op != '!' && op != '~') 0 0 0
if (op != '=' && op != '*' && op != '!' && op != '~') 0 0 0
if (op != '=' && op != '*' && op != '!' && op != '~') 0 0 0
741 0 op = 0 ;
742 else
743 0 p++ ;
744  
745 0 ▶ if (*p == '-')
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '-') 0 0 0
746 0 out = 0, p++ ;
747 0 ▶ else if (*p == '\'')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == '\'') 0 0 0
748 0 out = 2, p++ ;
749 0 ▶ else if (*p == '"')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == '"') 0 0 0
750 0 out = 3, p++ ;
751  
752
753 0 ▶ if (type == '#')
Branch: 1 branch
BranchTrueFalseTotal
if (type == '#') 0 0 0
754 {
755 0 ▶ if (!embperl_CompileAddChildNode (r, pDomTree, pNode ,p, q, op, out, ppCode))
Branch: 1 branch
BranchTrueFalseTotal
if (!embperl_CompileAddChildNode (r, pDomTree, pNode ,p, q, op, out, ppCode)) 0 0 0
756 {
757 0 valid = 0 ;
758 0 break ;
759 }
760 }
761 0 ▶ else if (type == '>')
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '>') 0 0 0
762 {
763 0 ▶ if (!embperl_CompileAddSiblingNode (r, pDomTree, pNode ,p, q, op, out, ppCode))
Branch: 1 branch
BranchTrueFalseTotal
if (!embperl_CompileAddSiblingNode (r, pDomTree, pNode ,p, q, op, out, ppCode)) 0 0 0
764 {
765 0 valid = 0 ;
766 0 break ;
767 }
768 }
769 0 ▶ else if (type == '&')
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '&') 0 0 0
770 {
771 0 ▶ if (!embperl_CompileAddAttribut (r, pDomTree, pNode ,p, q, op, out, ppCode))
Branch: 1 branch
BranchTrueFalseTotal
if (!embperl_CompileAddAttribut (r, pDomTree, pNode ,p, q, op, out, ppCode)) 0 0 0
772 {
773 0 valid = 0 ;
774 0 break ;
775 }
776 }
777 0 ▶ else if (type == '^')
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '^') 0 0 0
778 {
779 0 ▶ if (!embperl_CompileAddStack (r, pDomTree, p, q, op, out, 1, ppCode))
Branch: 1 branch
BranchTrueFalseTotal
if (!embperl_CompileAddStack (r, pDomTree, p, q, op, out, 1, ppCode)) 0 0 0
780 {
781 0 valid = 0 ;
782 0 break ;
783 }
784 }
785 0 ▶ else if (type == '?')
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '?') 0 0 0
786 {
787 0 ▶ if (!embperl_CompileAddStack (r, pDomTree, p, q, op, out, 0, ppCode))
Branch: 1 branch
BranchTrueFalseTotal
if (!embperl_CompileAddStack (r, pDomTree, p, q, op, out, 0, ppCode)) 0 0 0
788 {
789 0 valid = 0 ;
790 0 break ;
791 }
792 }
793 0 ▶ else if (type == '%')
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '%') 0 0 0
794 {
795 0 StringAdd (r -> pApp, ppCode, "%", 1) ;
796 }
797 0 ▶ else if (type == '$')
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '$') 0 0 0
798 {
799 0 ▶ if (*p == 'n')
Branch: 1 branch
BranchTrueFalseTotal
if (*p == 'n') 0 0 0
800 {
801 char s [20] ;
802 0 int l = sprintf (s, "$_ep_DomTree,%ld", pNode -> xNdx) ;
803 0 StringAdd (r -> pApp, ppCode, s, l) ;
804 }
805 0 ▶ else if (*p == 't')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == 't') 0 0 0
806 {
807 0 StringAdd (r -> pApp, ppCode, "$_ep_DomTree", 0) ;
808 }
809 0 ▶ else if (*p == 'x')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == 'x') 0 0 0
810 {
811 char s [20] ;
812 0 int l = sprintf (s, "%ld", pNode -> xNdx) ;
813 0 StringAdd (r -> pApp, ppCode, s, l) ;
814 }
815 0 ▶ else if (*p == 'l')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == 'l') 0 0 0
816 {
817 char s [20] ;
818 0 int l = sprintf (s, "%ld", pDomTree -> xLastNode) ;
819 0 StringAdd (r -> pApp, ppCode, s, l) ;
820 }
821 0 ▶ else if (*p == 'c')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == 'c') 0 0 0
822 {
823 char s [20] ;
824 0 ▶ if (pDomTree -> xLastNode != pDomTree -> xCurrNode)
Branch: 1 branch
BranchTrueFalseTotal
if (pDomTree -> xLastNode != pDomTree -> xCurrNode) 0 0 0
825 {
826 0 int l = sprintf (s, "$_ep_node=%ld;", pDomTree -> xLastNode) ;
827 0 StringAdd (r -> pApp, ppCode, s, l) ;
828 0 xCurrNode = pDomTree -> xLastNode ;
829 }
830 }
831 0 ▶ else if (*p == 'q')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == 'q') 0 0 0
832 {
833 char s [20] ;
834 0 int l = sprintf (s, "%hd", pDomTree -> xNdx) ;
835 0 StringAdd (r -> pApp, ppCode, s, l) ;
836 }
837 0 ▶ else if (*p == 'p')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == 'p') 0 0 0
838 {
839 char s [20] ;
840 0 int l = sprintf (s, "%u", ArrayGetSize (r -> pApp, pDomTree -> pCheckpoints)) ;
841 0 StringAdd (r -> pApp, ppCode, s, l) ;
842 }
843 0 ▶ else if (*p == 'k')
Branch: 1 branch
BranchTrueFalseTotal
else if (*p == 'k') 0 0 0
844 {
845 char s [40] ;
846 int l ;
847 0 tIndex nCheckpointArrayOffset = ArrayAdd (r -> pApp, &pDomTree -> pCheckpoints, 1) ;
848 0 pDomTree -> pCheckpoints[nCheckpointArrayOffset].xNode = pNode -> xNdx ;
849 0 l = sprintf (s, " _ep_cp(%ld) ;\n", nCheckpointArrayOffset) ;
850 0 StringAdd (r -> pApp, ppCode, s, l) ;
851  
852 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
853 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Checkpoint\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
854 }
855
856
857 }
858  
859 0 sPerlCode = q + 1 ;
860 0 p = strchr (sPerlCode, '%') ;
861 }
862 else
863 {
864 0 sPerlCode = p ;
865 0 p = NULL ;
866 }
867 }
868 0 ▶ if (valid)
Branch: 1 branch
BranchTrueFalseTotal
if (valid) 0 0 0
869 {
870 0 StringAdd (r -> pApp, ppCode, sPerlCode, 0) ;
871 0 ▶ if (xCurrNode)
Branch: 1 branch
BranchTrueFalseTotal
if (xCurrNode) 0 0 0
872 0 pDomTree -> xCurrNode = xCurrNode ;
873 }
874
875 }
876 0 return valid ;
877 }
878  
879  
880 /* ------------------------------------------------------------------------ */
881 /* */
882 /* embperl_CompileCleanupSpaces */
883 /* */
884 /* remove any following spaces */
885 /* */
886 /* ------------------------------------------------------------------------ */
887  
888  
889 0 static int embperl_CompileCleanupSpaces (/*in*/ tReq * r,
890 /*in*/ tDomTree * pDomTree,
891 /*in*/ tNodeData * pNode,
892 /*i/o*/ tEmbperlCmd * pCmd)
893  
894  
895 {
896 0 ▶ if ((pCmd -> bRemoveNode & 6) && (r -> Component.Config.bOptions & optKeepSpaces) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if ((pCmd -> bRemoveNode & 6) && (r -> Component.Config.bOptions & optKeepSpaces) == 0) 0 0 0
if ((pCmd -> bRemoveNode & 6) && (r -> Component.Config.bOptions & optKeepSpaces) == 0) 0 0 0
897 {
898 0 ▶ tNodeData * pNextNode = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0) ;
Branch: 2 branches
BranchTrueFalseTotal
tNodeData * pNextNode = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0) ; 0 0 0
tNodeData * pNextNode = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0) ; 0 0 0
899 0 ▶ if ((pCmd -> bRemoveNode & 1) || !pCmd -> bCompileChilds || pNextNode == NULL || (pNextNode -> nType != ntypText && pNextNode -> nType != ntypCDATA))
Branch: 5 branches
BranchTrueFalseTotal
if ((pCmd -> bRemoveNode & 1) || !pCmd -> bCompileChilds || pNextNode == NULL || (pNextNode -> nType != ntypText && pNextNode -> nType != ntypCDATA)) 0 0 0
if ((pCmd -> bRemoveNode & 1) || !pCmd -> bCompileChilds || pNextNode == NULL || (pNextNode -> nType != ntypText && pNextNode -> nType != ntypCDATA)) 0 0 0
if ((pCmd -> bRemoveNode & 1) || !pCmd -> bCompileChilds || pNextNode == NULL || (pNextNode -> nType != ntypText && pNextNode -> nType != ntypCDATA)) 0 0 0
if ((pCmd -> bRemoveNode & 1) || !pCmd -> bCompileChilds || pNextNode == NULL || (pNextNode -> nType != ntypText && pNextNode -> nType != ntypCDATA)) 0 0 0
if ((pCmd -> bRemoveNode & 1) || !pCmd -> bCompileChilds || pNextNode == NULL || (pNextNode -> nType != ntypText && pNextNode -> nType != ntypCDATA)) 0 0 0
900 0 pNextNode = Node_selfNextSibling (r -> pApp, pDomTree, pNode, 0) ;
901 0 ▶ if (pNextNode)
Branch: 1 branch
BranchTrueFalseTotal
if (pNextNode) 0 0 0
902 {
903 0 const char * sText = Node_selfNodeName (pNextNode) ;
904 0 const char * p = sText ;
905  
906 0 ▶ while (*p && isspace (*p))
Branch: 2 branches
BranchTrueFalseTotal
while (*p && isspace (*p)) 0 0 0
while (*p && isspace (*p)) 0 0 0
907 0 p++;
908 0 ▶ if (p > sText && (pCmd -> bRemoveNode & 4))
Branch: 2 branches
BranchTrueFalseTotal
if (p > sText && (pCmd -> bRemoveNode & 4)) 0 0 0
if (p > sText && (pCmd -> bRemoveNode & 4)) 0 0 0
909 0 p-- ;
910  
911 0 ▶ if (p > sText)
Branch: 1 branch
BranchTrueFalseTotal
if (p > sText) 0 0 0
912 { /* remove spaces */
913 0 ▶ if (*p)
Branch: 1 branch
BranchTrueFalseTotal
if (*p) 0 0 0
914 0 Node_replaceChildWithCDATA(r -> pApp, pDomTree, pNextNode -> xNdx, 0, p, strlen (p), -1, 0) ;
915 else
916 0 Node_selfRemoveChild(r -> pApp, pDomTree, -1, pNextNode) ;
917 }
918  
919 }
920 }
921 0 return ok ;
922 }
923  
924  
925  
926 /* ------------------------------------------------------------------------ */
927 /* */
928 /* embperl_CompileCmd */
929 /* */
930 /* Compile one cmd of one node */
931 /* */
932 /* ------------------------------------------------------------------------ */
933  
934  
935 0 static int embperl_CompileCmd (/*in*/ tReq * r,
936 /*in*/ tDomTree * pDomTree,
937 /*in*/ tNodeData * pNode,
938 /*in*/ tEmbperlCmd * pCmd,
939 /*out*/ int * nStartCodeOffset)
940  
941  
942 {
943 epTHX_
944 0 char * pCode = NULL ;
945 0 char * pCTCode = NULL ;
946 char * sSourcefile ;
947 int nSourcefile ;
948 int i ;
949 SV * args[4] ;
950 0 int nCodeLen = 0 ;
951 0 int found = 0 ;
952 0 char *use_utf8 = "" ;
953  
954 0 ▶ if (strcmp (r -> Component.Config.sInputCharset, "utf8") == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp (r -> Component.Config.sInputCharset, "utf8") == 0) 0 0 0
955 0 use_utf8 = "use utf8;" ;
956
957 0 r -> Component.pCodeSV = NULL ;
958  
959 0 Ndx2StringLen (pDomTree -> xFilename, sSourcefile, nSourcefile) ;
960  
961 0 ▶ if (pCmd -> nNodeType != pNode -> nType)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> nNodeType != pNode -> nType) 0 0 0
962 0 return ok ;
963  
964 0 ▶ for (i = 0; i < pCmd -> numPerlCode; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < pCmd -> numPerlCode; i++) 0 0 0
965 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPerlCode[i], &pCode))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPerlCode[i], &pCode)) 0 0 0
966 {
967 0 found = 1 ;
968 0 break ;
969 }
970  
971 0 ▶ if (found && pCode)
Branch: 2 branches
BranchTrueFalseTotal
if (found && pCode) 0 0 0
if (found && pCode) 0 0 0
972 {
973 0 nCodeLen = ArrayGetSize (r -> pApp, pCode) ;
974  
975 0 ▶ if (nCodeLen)
Branch: 1 branch
BranchTrueFalseTotal
if (nCodeLen) 0 0 0
976 {
977 char buf [32] ;
978  
979 0 ▶ if (pNode -> nLinenumber && pNode -> nLinenumber != pDomTree -> nLastLinenumber )
Branch: 2 branches
BranchTrueFalseTotal
if (pNode -> nLinenumber && pNode -> nLinenumber != pDomTree -> nLastLinenumber ) 0 0 0
if (pNode -> nLinenumber && pNode -> nLinenumber != pDomTree -> nLastLinenumber ) 0 0 0
980 {
981 0 int l2 = sprintf (buf, "#line %d \"", pDomTree -> nLastLinenumber = pNode -> nLinenumber) ;
982  
983 0 StringAdd (r -> pApp, r -> Component.pProg, buf, l2) ;
984 0 StringAdd (r -> pApp, r -> Component.pProg, sSourcefile, nSourcefile) ;
985 0 StringAdd (r -> pApp, r -> Component.pProg, "\"\n", 2) ;
986 }
987  
988 0 ▶ if (pCmd -> bPerlCodeRemove)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> bPerlCodeRemove) 0 0 0
989 0 *nStartCodeOffset = StringAdd (r -> pApp, r -> Component.pProg, " ", 1) ;
990 }
991 else
992 {
993 0 StringFree (r -> pApp, &pCode) ;
994 0 pCode = NULL ;
995 }
996 }
997 else
998 {
999 0 StringFree (r -> pApp, &pCode) ;
1000 0 pCode = NULL ;
1001 }
1002  
1003 0 ▶ for (i = 0; i < pCmd -> numCompileTimePerlCode; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < pCmd -> numCompileTimePerlCode; i++) 0 0 0
1004 {
1005 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sCompileTimePerlCode[i], &pCTCode))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sCompileTimePerlCode[i], &pCTCode)) 0 0 0
1006 {
1007 SV * pSV ;
1008 int rc ;
1009  
1010 0 ▶ if (pCTCode)
Branch: 1 branch
BranchTrueFalseTotal
if (pCTCode) 0 0 0
1011 {
1012 0 int l = ArrayGetSize (r -> pApp, pCTCode) ;
1013 0 int i = l ;
1014 0 char *p = pCTCode ;
1015  
1016 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1017 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d CompileTimeCode: %*.*s\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber, l, l, pCTCode) ;
1018  
1019 0 ▶ if (p[0] == '#' && p[1] == '!' && p[2] == '-')
Branch: 3 branches
BranchTrueFalseTotal
if (p[0] == '#' && p[1] == '!' && p[2] == '-') 0 0 0
if (p[0] == '#' && p[1] == '!' && p[2] == '-') 0 0 0
if (p[0] == '#' && p[1] == '!' && p[2] == '-') 0 0 0
1020 {
1021 0 p[0] = ' ' ;
1022 0 p[1] = ' ' ;
1023 0 p[2] = ' ' ;
1024 0 ▶ while (i--)
Branch: 1 branch
BranchTrueFalseTotal
while (i--) 0 0 0
1025 { /* keep everything on one line, to make linenumbers correct */
1026 0 ▶ if (*p == '\r' || *p == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\r' || *p == '\n') 0 0 0
if (*p == '\r' || *p == '\n') 0 0 0
1027 0 *p = ' ' ;
1028 0 p++ ;
1029 }
1030 }
1031  
1032 0 pSV = newSVpvf("package %s ; %s\n#line %d \"%s\"\n%*.*s",
1033 r -> Component.sEvalPackage, use_utf8, pNode -> nLinenumber, sSourcefile, l,l, pCTCode) ;
1034 newSVpvf2(pSV) ;
1035 0 args[0] = r -> _perlsv ;
1036 0 ▶ if (pCode)
Branch: 1 branch
BranchTrueFalseTotal
if (pCode) 0 0 0
1037 {
1038 0 r -> Component.pCodeSV = newSVpv (pCode, nCodeLen) ;
1039 }
1040 else
1041 0 r -> Component.pCodeSV = &sv_undef ;
1042 0 ▶ SvTAINTED_off (pSV) ;
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_off (pSV) ; 0 0 0
1043 0 ▶ if ((rc = EvalDirect (r, pSV, 1, args)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = EvalDirect (r, pSV, 1, args)) != ok) 0 0 0
1044 0 LogError (r, rc) ;
1045 0 SvREFCNT_dec(pSV);
1046 }
1047 0 break ;
1048 }
1049 }
1050  
1051 0 ▶ if (r -> Component.pCodeSV && SvOK(r -> Component.pCodeSV))
Branch: 2 branches
BranchTrueFalseTotal
if (r -> Component.pCodeSV && SvOK(r -> Component.pCodeSV)) 0 0 0
if (r -> Component.pCodeSV && SvOK(r -> Component.pCodeSV)) 0 0 0
1052 0 {
1053 STRLEN l ;
1054 0 char * p = SvPV (r -> Component.pCodeSV, l) ;
1055 0 StringAdd (r -> pApp, r -> Component.pProg, p, l ) ;
1056 0 StringAdd (r -> pApp, r -> Component.pProg, "\n", 1) ;
1057 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1058 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Code: %s\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber, p) ;
1059 }
1060 0 ▶ else if (pCode)
Branch: 1 branch
BranchTrueFalseTotal
else if (pCode) 0 0 0
1061 {
1062 0 StringAdd (r -> pApp, r -> Component.pProg, pCode, nCodeLen ) ;
1063 0 StringAdd (r -> pApp, r -> Component.pProg, "\n", 1) ;
1064 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1065 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Code: %*.*s\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber, nCodeLen, nCodeLen, pCode) ;
1066 }
1067
1068 0 StringFree (r -> pApp, &pCode) ;
1069 0 StringFree (r -> pApp, &pCTCode) ;
1070  
1071 0 ▶ if (r -> Component.pCodeSV)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pCodeSV) 0 0 0
1072 {
1073 0 SvREFCNT_dec(r -> Component.pCodeSV);
1074 0 r -> Component.pCodeSV = NULL ;
1075 }
1076 0 return ok ;
1077 }
1078  
1079  
1080  
1081 /* ------------------------------------------------------------------------ */
1082 /* */
1083 /* embperl_CompilePostProcess */
1084 /* */
1085 /* Do some postprocessing after compiling */
1086 /* */
1087 /* ------------------------------------------------------------------------ */
1088  
1089  
1090 0 static int embperl_CompilePostProcess (/*in*/ tReq * r,
1091 /*in*/ tDomTree * pDomTree,
1092 /*in*/ tNodeData * pNode,
1093 /*in*/ tEmbperlCmd * pCmd,
1094 /*in*/ int nCheckpointCodeOffset,
1095 /*in*/ int nCheckpointArrayOffset,
1096 /*i/o*/ int * bCheckpointPending)
1097  
1098  
1099 {
1100 int rc ;
1101 0 char * sStackValue = NULL ;
1102  
1103  
1104 0 embperl_CompileCleanupSpaces (r, pDomTree, pNode, pCmd) ;
1105  
1106 0 ▶ if (pCmd -> sMayJump)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> sMayJump) 0 0 0
1107 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sMayJump, &sStackValue))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sMayJump, &sStackValue)) 0 0 0
1108 {
1109 0 ▶ if (*bCheckpointPending <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (*bCheckpointPending <= 0) 0 0 0
1110 0 *bCheckpointPending = -1 ;
1111 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1112 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Set Checkpoint pending\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
1113 }
1114  
1115 0 ▶ if (pCmd -> bRemoveNode & 1)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> bRemoveNode & 1) 0 0 0
1116 0 pNode -> bFlags = 0 ;
1117 0 ▶ else if (pCmd -> bRemoveNode & 8)
Branch: 1 branch
BranchTrueFalseTotal
else if (pCmd -> bRemoveNode & 8) 0 0 0
1118 0 pNode -> bFlags |= nflgIgnore ;
1119 0 ▶ if (pCmd -> bRemoveNode & 16)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> bRemoveNode & 16) 0 0 0
1120 {
1121 tNodeData * pChild ;
1122 0 ▶ while ((pChild = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0)))
Branch: 3 branches
BranchTrueFalseTotal
while ((pChild = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0))) 0 0 0
while ((pChild = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0))) 0 0 0
while ((pChild = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0))) 0 0 0
1123 {
1124 0 Node_selfRemoveChild (r -> pApp, pDomTree, pNode -> xNdx, pChild) ;
1125 }
1126 }
1127 0 ▶ else if (pCmd -> bRemoveNode & 32)
Branch: 1 branch
BranchTrueFalseTotal
else if (pCmd -> bRemoveNode & 32) 0 0 0
1128 {
1129 0 ▶ tNodeData * pChild = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0) ;
Branch: 2 branches
BranchTrueFalseTotal
tNodeData * pChild = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0) ; 0 0 0
tNodeData * pChild = Node_selfFirstChild (r -> pApp, pDomTree, pNode, 0) ; 0 0 0
1130 0 ▶ while (pChild)
Branch: 1 branch
BranchTrueFalseTotal
while (pChild) 0 0 0
1131 {
1132 0 pChild -> bFlags |= nflgIgnore ;
1133 0 pChild = Node_selfNextSibling (r -> pApp, pDomTree, pChild, 0) ;
1134  
1135 }
1136 }
1137  
1138  
1139 0 ▶ if (nCheckpointCodeOffset && (pNode -> bFlags == 0 || (pNode -> bFlags & nflgIgnore)))
Branch: 3 branches
BranchTrueFalseTotal
if (nCheckpointCodeOffset && (pNode -> bFlags == 0 || (pNode -> bFlags & nflgIgnore))) 0 0 0
if (nCheckpointCodeOffset && (pNode -> bFlags == 0 || (pNode -> bFlags & nflgIgnore))) 0 0 0
if (nCheckpointCodeOffset && (pNode -> bFlags == 0 || (pNode -> bFlags & nflgIgnore))) 0 0 0
1140 {
1141 0 (*r -> Component.pProg)[nCheckpointCodeOffset] = '#' ;
1142 0 nCheckpointArrayOffset = ArraySub (r -> pApp, &pDomTree -> pCheckpoints, 1) ;
1143 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1144 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Remove Checkpoint\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
1145 0 nCheckpointCodeOffset = 0 ;
1146 0 ▶ if (*bCheckpointPending <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (*bCheckpointPending <= 0) 0 0 0
1147 0 *bCheckpointPending = -1 ; /* set checkpoint on next possibility */
1148 }
1149  
1150 0 ▶ if (*bCheckpointPending < 0 && (pNode -> bFlags & nflgIgnore))
Branch: 2 branches
BranchTrueFalseTotal
if (*bCheckpointPending < 0 && (pNode -> bFlags & nflgIgnore)) 0 0 0
if (*bCheckpointPending < 0 && (pNode -> bFlags & nflgIgnore)) 0 0 0
1151 {
1152 int l ;
1153 char buf [80] ;
1154  
1155 0 nCheckpointArrayOffset = ArrayAdd (r -> pApp, &pDomTree -> pCheckpoints, 1) ;
1156 0 pDomTree -> pCheckpoints[nCheckpointArrayOffset].xNode = pNode -> xNdx ;
1157 0 *bCheckpointPending = 0 ;
1158 0 l = sprintf (buf, " _ep_cp(%d) ;\n", nCheckpointArrayOffset) ;
1159 0 nCheckpointCodeOffset = StringAdd (r -> pApp, r -> Component.pProg, buf, l) ;
1160  
1161 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1162 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Checkpoint\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
1163  
1164 }
1165  
1166 0 ▶ if (pCmd -> sPopStack)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> sPopStack) 0 0 0
1167 0 embperl_CompilePopStack (r, pDomTree, pCmd -> sPopStack) ;
1168 0 ▶ if (pCmd -> sPopStack2)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> sPopStack2) 0 0 0
1169 0 embperl_CompilePopStack (r, pDomTree, pCmd -> sPopStack2) ;
1170  
1171 0 ▶ if (pCmd -> sStackName)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> sStackName) 0 0 0
1172 {
1173 0 ▶ if (pCmd -> sMatchStack && pNode -> nType != ntypStartTag && pNode -> nType != ntypDocument && pNode -> nType != ntypDocumentFraq)
Branch: 4 branches
BranchTrueFalseTotal
if (pCmd -> sMatchStack && pNode -> nType != ntypStartTag && pNode -> nType != ntypDocument && pNode -> nType != ntypDocumentFraq) 0 0 0
if (pCmd -> sMatchStack && pNode -> nType != ntypStartTag && pNode -> nType != ntypDocument && pNode -> nType != ntypDocumentFraq) 0 0 0
if (pCmd -> sMatchStack && pNode -> nType != ntypStartTag && pNode -> nType != ntypDocument && pNode -> nType != ntypDocumentFraq) 0 0 0
if (pCmd -> sMatchStack && pNode -> nType != ntypStartTag && pNode -> nType != ntypDocument && pNode -> nType != ntypDocumentFraq) 0 0 0
1174 {
1175 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sMatchStack, &sStackValue))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sMatchStack, &sStackValue)) 0 0 0
1176 0 ▶ if ((rc = embperl_CompileMatchStack (r, pDomTree, pNode, pCmd -> sStackName, sStackValue)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = embperl_CompileMatchStack (r, pDomTree, pNode, pCmd -> sStackName, sStackValue)) != ok) 0 0 0
1177 {
1178 0 StringFree (r -> pApp, &sStackValue) ;
1179 0 return rc ;
1180 }
1181 }
1182 0 ▶ if (pCmd -> sPushStack)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> sPushStack) 0 0 0
1183 {
1184 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPushStack, &sStackValue))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPushStack, &sStackValue)) 0 0 0
1185 0 embperl_CompilePushStack (r, pDomTree, pCmd -> sStackName, sStackValue) ;
1186 }
1187 }
1188 0 ▶ if (pCmd -> sStackName2 && pCmd -> sPushStack2)
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd -> sStackName2 && pCmd -> sPushStack2) 0 0 0
if (pCmd -> sStackName2 && pCmd -> sPushStack2) 0 0 0
1189 {
1190 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPushStack2, &sStackValue))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPushStack2, &sStackValue)) 0 0 0
1191 {
1192 0 embperl_CompilePushStack (r, pDomTree, pCmd -> sStackName2, sStackValue) ;
1193 }
1194 }
1195  
1196 0 StringFree (r -> pApp, &sStackValue) ;
1197  
1198 0 return ok ;
1199 }
1200
1201
1202  
1203  
1204  
1205 /* ------------------------------------------------------------------------ */
1206 /* */
1207 /* embperl_CompileCmdEnd */
1208 /* */
1209 /* Compile the end of the node */
1210 /* */
1211 /* ------------------------------------------------------------------------ */
1212  
1213  
1214 0 static int embperl_CompileCmdEnd (/*in*/ tReq * r,
1215 /*in*/ tDomTree * pDomTree,
1216 /*in*/ tNodeData * pNode,
1217 /*in*/ tEmbperlCmd * pCmd,
1218 /*in*/ int nStartCodeOffset,
1219 /*i/o*/ int * bCheckpointPending)
1220  
1221  
1222 {
1223 epTHX_
1224 int rc ;
1225 0 char * sStackValue = NULL ;
1226 0 char * pCode = NULL ;
1227 0 char * pCTCode = NULL ;
1228 SV * args[4] ;
1229 0 STRLEN nCodeLen = 0 ;
1230 0 char *use_utf8 = "" ;
1231  
1232 0 ▶ if (strcmp (r -> Component.Config.sInputCharset, "utf8") == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp (r -> Component.Config.sInputCharset, "utf8") == 0) 0 0 0
1233 0 use_utf8 = "use utf8;" ;
1234  
1235  
1236 0 ▶ if (pCmd -> nNodeType != pNode -> nType)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> nNodeType != pNode -> nType) 0 0 0
1237 0 return ok ;
1238  
1239  
1240 0 ▶ if (pCmd)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd) 0 0 0
1241 {
1242 0 ▶ if (pCmd -> sPerlCodeEnd && embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPerlCodeEnd, &pCode))
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd -> sPerlCodeEnd && embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPerlCodeEnd, &pCode)) 0 0 0
if (pCmd -> sPerlCodeEnd && embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sPerlCodeEnd, &pCode)) 0 0 0
1243 0 nCodeLen = ArrayGetSize (r -> pApp, pCode) ;
1244
1245 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sCompileTimePerlCodeEnd, &pCTCode))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sCompileTimePerlCodeEnd, &pCTCode)) 0 0 0
1246 {
1247 SV * pSV ;
1248 int rc ;
1249  
1250 0 ▶ if (pCTCode && *pCTCode)
Branch: 2 branches
BranchTrueFalseTotal
if (pCTCode && *pCTCode) 0 0 0
if (pCTCode && *pCTCode) 0 0 0
1251 {
1252 0 int l = ArrayGetSize (r -> pApp, pCTCode) ;
1253 char * sSourcefile ;
1254 int nSourcefile ;
1255 0 int i = l ;
1256 0 char * p = pCTCode ;
1257
1258 0 Ndx2StringLen (pDomTree -> xFilename, sSourcefile, nSourcefile) ;
1259  
1260 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1261 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d CompileTimeCodeEnd: %*.*s\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber, l, l, pCTCode) ;
1262  
1263 0 ▶ if (p[0] == '#' && p[1] == '!' && p[2] == '-')
Branch: 3 branches
BranchTrueFalseTotal
if (p[0] == '#' && p[1] == '!' && p[2] == '-') 0 0 0
if (p[0] == '#' && p[1] == '!' && p[2] == '-') 0 0 0
if (p[0] == '#' && p[1] == '!' && p[2] == '-') 0 0 0
1264 {
1265 0 p[0] = ' ' ;
1266 0 p[1] = ' ' ;
1267 0 p[2] = ' ' ;
1268 0 ▶ while (i--)
Branch: 1 branch
BranchTrueFalseTotal
while (i--) 0 0 0
1269 { /* keep everything on one line, to make linenumbers correct */
1270 0 ▶ if (*p == '\r' || *p == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\r' || *p == '\n') 0 0 0
if (*p == '\r' || *p == '\n') 0 0 0
1271 0 *p = ' ' ;
1272 0 p++ ;
1273 }
1274 }
1275  
1276
1277 0 pSV = newSVpvf("package %s ; %s\n#line %d \"%s\"\n%*.*s",
1278 r -> Component.sEvalPackage, use_utf8, pNode -> nLinenumber, sSourcefile, l,l, pCTCode) ;
1279 newSVpvf2(pSV) ;
1280 0 args[0] = r -> _perlsv ;
1281 0 ▶ if (pCode)
Branch: 1 branch
BranchTrueFalseTotal
if (pCode) 0 0 0
1282 {
1283 0 r -> Component.pCodeSV = newSVpv (pCode, nCodeLen) ;
1284 }
1285 else
1286 0 r -> Component.pCodeSV = &sv_undef ;
1287 0 ▶ if ((rc = EvalDirect (r, pSV, 1, args)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = EvalDirect (r, pSV, 1, args)) != ok) 0 0 0
1288 0 LogError (r, rc) ;
1289 0 SvREFCNT_dec(pSV);
1290 }
1291 }
1292  
1293 0 ▶ if (r -> Component.pCodeSV)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pCodeSV) 0 0 0
1294 {
1295 0 ▶ if (SvOK (r -> Component.pCodeSV))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK (r -> Component.pCodeSV)) 0 0 0
1296 {
1297 0 char * p = SvPV (r -> Component.pCodeSV, nCodeLen) ;
1298 0 ▶ if (nCodeLen)
Branch: 1 branch
BranchTrueFalseTotal
if (nCodeLen) 0 0 0
1299 {
1300 0 StringAdd (r -> pApp, r -> Component.pProg, p, nCodeLen ) ;
1301 0 StringAdd (r -> pApp, r -> Component.pProg, "\n", 1) ;
1302 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1303 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d CodeEnd: %s\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber, p) ;
1304 }
1305 }
1306 }
1307 0 ▶ else if (pCode && nCodeLen)
Branch: 2 branches
BranchTrueFalseTotal
else if (pCode && nCodeLen) 0 0 0
else if (pCode && nCodeLen) 0 0 0
1308 {
1309 0 StringAdd (r -> pApp, r -> Component.pProg, pCode, nCodeLen ) ;
1310 0 StringAdd (r -> pApp, r -> Component.pProg, "\n", 1) ;
1311 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1312 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d CodeEnd: %*.*s\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber, nCodeLen, nCodeLen, pCode) ;
1313 }
1314 0 ▶ if (nCodeLen == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (nCodeLen == 0) 0 0 0
1315 {
1316 0 ▶ if (pCmd -> bPerlCodeRemove && nStartCodeOffset)
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd -> bPerlCodeRemove && nStartCodeOffset) 0 0 0
if (pCmd -> bPerlCodeRemove && nStartCodeOffset) 0 0 0
1317 {
1318 0 (*r -> Component.pProg)[nStartCodeOffset] = '#' ;
1319 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1320 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Remove Codeblock\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
1321 }
1322 }
1323 0 ▶ if (pCmd -> sPerlCodeEnd && pCmd -> sMayJump)
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd -> sPerlCodeEnd && pCmd -> sMayJump) 0 0 0
if (pCmd -> sPerlCodeEnd && pCmd -> sMayJump) 0 0 0
1324 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sMayJump, &sStackValue))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sMayJump, &sStackValue)) 0 0 0
1325 {
1326 0 ▶ if (*bCheckpointPending <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (*bCheckpointPending <= 0) 0 0 0
1327 0 *bCheckpointPending = -1 ;
1328 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1329 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Set Checkpoint pending\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
1330 }
1331 0 ▶ if (pCmd -> sStackName && (pNode -> nType == ntypStartTag || pNode -> nType == ntypDocument || pNode -> nType == ntypDocumentFraq))
Branch: 4 branches
BranchTrueFalseTotal
if (pCmd -> sStackName && (pNode -> nType == ntypStartTag || pNode -> nType == ntypDocument || pNode -> nType == ntypDocumentFraq)) 0 0 0
if (pCmd -> sStackName && (pNode -> nType == ntypStartTag || pNode -> nType == ntypDocument || pNode -> nType == ntypDocumentFraq)) 0 0 0
if (pCmd -> sStackName && (pNode -> nType == ntypStartTag || pNode -> nType == ntypDocument || pNode -> nType == ntypDocumentFraq)) 0 0 0
if (pCmd -> sStackName && (pNode -> nType == ntypStartTag || pNode -> nType == ntypDocument || pNode -> nType == ntypDocumentFraq)) 0 0 0
1332 {
1333 0 ▶ if (pCmd -> sMatchStack)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> sMatchStack) 0 0 0
1334 {
1335 0 ▶ if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sMatchStack, &sStackValue))
Branch: 1 branch
BranchTrueFalseTotal
if (embperl_CompileToPerlCode (r, pDomTree, pNode, pCmd -> sMatchStack, &sStackValue)) 0 0 0
1336 {
1337 0 ▶ if ((rc = embperl_CompileMatchStack (r, pDomTree, pNode, pCmd -> sStackName, sStackValue)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = embperl_CompileMatchStack (r, pDomTree, pNode, pCmd -> sStackName, sStackValue)) != ok) 0 0 0
1338 {
1339 0 StringFree (r -> pApp, &pCode) ;
1340 0 StringFree (r -> pApp, &pCTCode) ;
1341 0 StringFree (r -> pApp, &sStackValue) ;
1342 0 return rc ;
1343 }
1344 }
1345 }
1346 0 ▶ else if (pCmd -> sPushStack && pCmd -> sPerlCodeEnd)
Branch: 2 branches
BranchTrueFalseTotal
else if (pCmd -> sPushStack && pCmd -> sPerlCodeEnd) 0 0 0
else if (pCmd -> sPushStack && pCmd -> sPerlCodeEnd) 0 0 0
1347 0 embperl_CompilePopStack (r, pDomTree, pCmd -> sStackName) ;
1348 }
1349  
1350 0 ▶ if (pCmd -> sStackName2 && pCmd -> sPushStack2 && pCmd -> sPerlCodeEnd)
Branch: 3 branches
BranchTrueFalseTotal
if (pCmd -> sStackName2 && pCmd -> sPushStack2 && pCmd -> sPerlCodeEnd) 0 0 0
if (pCmd -> sStackName2 && pCmd -> sPushStack2 && pCmd -> sPerlCodeEnd) 0 0 0
if (pCmd -> sStackName2 && pCmd -> sPushStack2 && pCmd -> sPerlCodeEnd) 0 0 0
1351 0 embperl_CompilePopStack (r, pDomTree, pCmd -> sStackName2) ;
1352
1353 0 ▶ if (pCmd -> nSwitchCodeType == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd -> nSwitchCodeType == 1) 0 0 0
1354 {
1355 0 r -> Component.pProg = &r -> Component.pProgRun ;
1356 0 ▶ if (*bCheckpointPending <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (*bCheckpointPending <= 0) 0 0 0
1357 0 *bCheckpointPending = -1 ;
1358 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1359 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Set Checkpoint pending (switch to ProgRun)\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
1360 }
1361 }
1362  
1363  
1364 0 StringFree (r -> pApp, &pCode) ;
1365 0 StringFree (r -> pApp, &pCTCode) ;
1366  
1367 0 ▶ if (r -> Component.pCodeSV)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pCodeSV) 0 0 0
1368 {
1369 0 SvREFCNT_dec(r -> Component.pCodeSV);
1370 0 r -> Component.pCodeSV = NULL ;
1371 }
1372
1373 0 StringFree (r -> pApp, &sStackValue) ;
1374  
1375 0 return ok ;
1376 }
1377  
1378  
1379 /* ------------------------------------------------------------------------ */
1380 /* */
1381 /* embperl_CompileNode */
1382 /* */
1383 /* Compile one node and his children */
1384 /* */
1385 /* ------------------------------------------------------------------------ */
1386  
1387  
1388 0 int embperl_CompileNode (/*in*/ tReq * r,
1389 /*in*/ tDomTree * pDomTree,
1390 /*in*/ tNode xNode,
1391 /*i/o*/ int * bCheckpointPending)
1392  
1393  
1394 {
1395 int rc ;
1396 tNode xChildNode ;
1397 tStringIndex nNdx ;
1398 tEmbperlCmd * pCmd ;
1399 tEmbperlCmd * pCmdHead ;
1400 tEmbperlCmd * pCmdLast ;
1401 tEmbperlCmd * pCmdNext ;
1402 tEmbperlCmd * pCmdIter ;
1403 0 tNodeData * pNode = Node_self (pDomTree, xNode) ;
1404 tAttrData * pAttr ;
1405 0 int nAttr = 0 ;
1406 0 int nStartCodeOffset = 0 ;
1407 0 int nCheckpointCodeOffset = 0 ;
1408 0 int nCheckpointArrayOffset = 0 ;
1409 0 tEmbperlCompilerInfo * pInfo = (tEmbperlCompilerInfo *)(*(void * *)r -> Component.pTokenTable) ;
1410 0 tIndex xDomTree = pDomTree -> xNdx ;
1411  
1412 0 pCmd = NULL ;
1413
1414 0 nNdx = Node_selfNodeNameNdx (pNode) ;
1415  
1416 0 ▶ if (nNdx <= pInfo -> nMaxEmbperlCmd)
Branch: 1 branch
BranchTrueFalseTotal
if (nNdx <= pInfo -> nMaxEmbperlCmd) 0 0 0
1417 {
1418 0 pCmd = pCmdHead = &(pInfo -> pEmbperlCmds[nNdx]) ;
1419 0 pCmdLast = NULL ;
1420 /* ??if (pCmd -> nNodeType != pNode -> nType) */
1421 /* pCmd = NULL ; */
1422 }
1423 else
1424 0 pCmd = pCmdHead = pCmdLast = NULL ;
1425
1426  
1427 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1428 {
1429 char buf[20] ;
1430 0 ▶ lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d -------> parent=%d node=%d type=%d text=%s (#%d,%s) %s\n",
Branch: 2 branches
BranchTrueFalseTotal
lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d -------> parent=%d node=%d type=%d text=%s (#%d,%s) %s\n", 0 0 0
lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d -------> parent=%d node=%d type=%d text=%s (#%d,%s) %s\n", 0 0 0
1431 0 r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber,
1432 0 ▶ Node_parentNode (r -> pApp, pDomTree, pNode -> xNdx, 0), pNode -> xNdx,
Branch: 1 branch
BranchTrueFalseTotal
Node_parentNode (r -> pApp, pDomTree, pNode -> xNdx, 0), pNode -> xNdx, 0 0 0
1433 0 ▶ pNode -> nType, Node_selfNodeName(pNode), nNdx, pCmd?"compile":"-", (pCmd && pCmd -> bRemoveNode)?(sprintf (buf, "removenode=%d", pCmd -> bRemoveNode), buf):"") ;
Branch: 2 branches
BranchTrueFalseTotal
pNode -> nType, Node_selfNodeName(pNode), nNdx, pCmd?"compile":"-", (pCmd && pCmd -> bRemoveNode)?(sprintf (buf, "removenode=%d", pCmd -> bRemoveNode), buf):"") ; 0 0 0
pNode -> nType, Node_selfNodeName(pNode), nNdx, pCmd?"compile":"-", (pCmd && pCmd -> bRemoveNode)?(sprintf (buf, "removenode=%d", pCmd -> bRemoveNode), buf):"") ; 0 0 0
1434 }
1435
1436  
1437 0 ▶ if (pCmd == NULL || (pCmd -> bRemoveNode & 1) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd == NULL || (pCmd -> bRemoveNode & 1) == 0) 0 0 0
if (pCmd == NULL || (pCmd -> bRemoveNode & 1) == 0) 0 0 0
1438 0 pDomTree -> xLastNode = xNode ;
1439  
1440 /* if (*bCheckpointPending && (pNode -> nType == ntypText || pNode -> nType == ntypCDATA) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0) */
1441 /* if (*bCheckpointPending && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0) */
1442 0 ▶ if (*bCheckpointPending < 0 && !(pCmd && pCmd -> nSwitchCodeType == 2) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0)
Branch: 5 branches
BranchTrueFalseTotal
if (*bCheckpointPending < 0 && !(pCmd && pCmd -> nSwitchCodeType == 2) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0) 0 0 0
if (*bCheckpointPending < 0 && !(pCmd && pCmd -> nSwitchCodeType == 2) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0) 0 0 0
if (*bCheckpointPending < 0 && !(pCmd && pCmd -> nSwitchCodeType == 2) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0) 0 0 0
if (*bCheckpointPending < 0 && !(pCmd && pCmd -> nSwitchCodeType == 2) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0) 0 0 0
if (*bCheckpointPending < 0 && !(pCmd && pCmd -> nSwitchCodeType == 2) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0) 0 0 0
1443 {
1444 int l ;
1445 char buf [80] ;
1446
1447 0 nCheckpointArrayOffset = ArrayAdd (r -> pApp, &pDomTree -> pCheckpoints, 1) ;
1448 0 pDomTree -> pCheckpoints[nCheckpointArrayOffset].xNode = xNode ;
1449 0 *bCheckpointPending = 0 ;
1450 0 l = sprintf (buf, " _ep_cp(%d) ;\n", nCheckpointArrayOffset) ;
1451 0 nCheckpointCodeOffset = StringAdd (r -> pApp, r -> Component.pProg, buf, l) ;
1452  
1453 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1454 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d L%d Checkpoint\n", r -> pThread -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
1455
1456 }
1457  
1458 0 ▶ if (pCmd && pCmd -> nSwitchCodeType == 2)
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd && pCmd -> nSwitchCodeType == 2) 0 0 0
if (pCmd && pCmd -> nSwitchCodeType == 2) 0 0 0
1459 {
1460 0 r -> Component.pProg = &r -> Component.pProgDef ;
1461 0 nCheckpointArrayOffset = 0 ;
1462 0 nCheckpointCodeOffset = 0 ;
1463 }
1464
1465 0 ▶ if (pCmd == NULL || (pCmd -> bRemoveNode & 8) == 0 || (pCmd -> bRemoveNode & 64))
Branch: 3 branches
BranchTrueFalseTotal
if (pCmd == NULL || (pCmd -> bRemoveNode & 8) == 0 || (pCmd -> bRemoveNode & 64)) 0 0 0
if (pCmd == NULL || (pCmd -> bRemoveNode & 8) == 0 || (pCmd -> bRemoveNode & 64)) 0 0 0
if (pCmd == NULL || (pCmd -> bRemoveNode & 8) == 0 || (pCmd -> bRemoveNode & 64)) 0 0 0
1466 { /* calculate attributes before tag, but not when tag should be ignored in output stream */
1467 0 int bSaveCP = *bCheckpointPending ;
1468 0 ▶ if (pCmd && (pCmd -> bRemoveNode & 64))
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd && (pCmd -> bRemoveNode & 64)) 0 0 0
if (pCmd && (pCmd -> bRemoveNode & 64)) 0 0 0
1469 0 *bCheckpointPending = 1 ;
1470
1471 0 ▶ while ((pAttr = Element_selfGetNthAttribut (r -> pApp, pDomTree, pNode, nAttr++)))
Branch: 1 branch
BranchTrueFalseTotal
while ((pAttr = Element_selfGetNthAttribut (r -> pApp, pDomTree, pNode, nAttr++))) 0 0 0
1472 {
1473 0 ▶ if (pAttr -> bFlags & aflgAttrChilds)
Branch: 1 branch
BranchTrueFalseTotal
if (pAttr -> bFlags & aflgAttrChilds) 0 0 0
1474 {
1475 0 ▶ tNodeData * pChild = Node_selfFirstChild (r -> pApp, pDomTree, (tNodeData *)pAttr, 0) ;
Branch: 2 branches
BranchTrueFalseTotal
tNodeData * pChild = Node_selfFirstChild (r -> pApp, pDomTree, (tNodeData *)pAttr, 0) ; 0 0 0
tNodeData * pChild = Node_selfFirstChild (r -> pApp, pDomTree, (tNodeData *)pAttr, 0) ; 0 0 0
1476 tNodeData * pNext ;
1477  
1478 0 ▶ while (pChild)
Branch: 1 branch
BranchTrueFalseTotal
while (pChild) 0 0 0
1479 {
1480 0 embperl_CompileNode (r, pDomTree, pChild -> xNdx, bCheckpointPending) ;
1481 0 pDomTree = DomTree_self (xDomTree) ; /* addr may have changed */
1482 0 pNext = Node_selfNextSibling (r -> pApp, pDomTree, pChild, 0) ;
1483 0 ▶ if (pChild -> bFlags == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (pChild -> bFlags == 0) 0 0 0
1484 0 Node_selfRemoveChild(r -> pApp, pDomTree, -1, pChild) ;
1485 0 pChild = pNext ;
1486 }
1487 }
1488  
1489 }
1490 0 ▶ if (pCmd && (pCmd -> bRemoveNode & 64))
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd && (pCmd -> bRemoveNode & 64)) 0 0 0
if (pCmd && (pCmd -> bRemoveNode & 64)) 0 0 0
1491 0 *bCheckpointPending = bSaveCP ;
1492  
1493 }
1494
1495  
1496 0 ▶ while (pCmd)
Branch: 1 branch
BranchTrueFalseTotal
while (pCmd) 0 0 0
1497 {
1498 0 ▶ if ((rc = embperl_CompileCmd (r, pDomTree, pNode, pCmd, &nStartCodeOffset)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = embperl_CompileCmd (r, pDomTree, pNode, pCmd, &nStartCodeOffset)) != ok) 0 0 0
1499 0 return rc ;
1500 0 pDomTree = DomTree_self (xDomTree) ; /* addr may have changed */
1501 0 pCmdLast = pCmd ;
1502 0 pCmd = pCmd -> pNext ;
1503 }
1504  
1505 0 pCmd = pCmdLast ;
1506 0 ▶ if (pCmd)
Branch: 1 branch
BranchTrueFalseTotal
if (pCmd) 0 0 0
1507 0 ▶ if ((rc = embperl_CompilePostProcess (r, pDomTree, pNode, pCmd, nCheckpointCodeOffset, nCheckpointArrayOffset, bCheckpointPending)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = embperl_CompilePostProcess (r, pDomTree, pNode, pCmd, nCheckpointCodeOffset, nCheckpointArrayOffset, bCheckpointPending)) != ok) 0 0 0
1508 0 return rc ;
1509  
1510  
1511 0 ▶ if (pCmd == NULL || pCmd -> bCompileChilds)
Branch: 2 branches
BranchTrueFalseTotal
if (pCmd == NULL || pCmd -> bCompileChilds) 0 0 0
if (pCmd == NULL || pCmd -> bCompileChilds) 0 0 0
1512 {
1513 tNodeData * pChildNode ;
1514  
1515 0 ▶ xChildNode = pNode -> bFlags?Node_firstChild (r -> pApp, pDomTree, xNode, 0):0 ;
Branch: 3 branches
BranchTrueFalseTotal
xChildNode = pNode -> bFlags?Node_firstChild (r -> pApp, pDomTree, xNode, 0):0 ; 0 0 0
xChildNode = pNode -> bFlags?Node_firstChild (r -> pApp, pDomTree, xNode, 0):0 ; 0 0 0
xChildNode = pNode -> bFlags?Node_firstChild (r -> pApp, pDomTree, xNode, 0):0 ; 0 0 0
1516  
1517 0 ▶ while (xChildNode)
Branch: 1 branch
BranchTrueFalseTotal
while (xChildNode) 0 0 0
1518 {
1519 0 ▶ if ((rc = embperl_CompileNode (r, pDomTree, xChildNode, bCheckpointPending)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = embperl_CompileNode (r, pDomTree, xChildNode, bCheckpointPending)) != ok) 0 0 0
1520 0 return rc ;
1521  
1522 0 pDomTree = DomTree_self (xDomTree) ; /* addr may have changed */
1523 0 pChildNode = Node_self (pDomTree, xChildNode) ;
1524 0 xChildNode = Node_nextSibling (r -> pApp, pDomTree, xChildNode, 0) ;
1525 0 ▶ if (pChildNode -> bFlags == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (pChildNode -> bFlags == 0) 0 0 0
1526 0 Node_selfRemoveChild(r -> pApp, pDomTree, -1, pChildNode) ;
1527 }
1528 }
1529
1530  
1531 0 ▶ while (pCmd)
Branch: 1 branch
BranchTrueFalseTotal
while (pCmd) 0 0 0
1532 {
1533 0 ▶ if ((rc = embperl_CompileCmdEnd (r, pDomTree, pNode, pCmd, nStartCodeOffset, bCheckpointPending)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = embperl_CompileCmdEnd (r, pDomTree, pNode, pCmd, nStartCodeOffset, bCheckpointPending)) != ok) 0 0 0
1534 0 return rc ;
1535 0 pCmdIter = pCmdHead ;
1536 0 pCmdNext = NULL ;
1537 0 ▶ while (pCmdIter && pCmdIter != pCmd)
Branch: 2 branches
BranchTrueFalseTotal
while (pCmdIter && pCmdIter != pCmd) 0 0 0
while (pCmdIter && pCmdIter != pCmd) 0 0 0
1538 {
1539 0 pCmdNext = pCmdIter ;
1540 0 pCmdIter = pCmdIter -> pNext ;
1541 }
1542 0 pCmd = pCmdNext ;
1543 }
1544  
1545 0 ▶ if (pCmdHead && pCmdHead -> nSwitchCodeType == 2)
Branch: 2 branches
BranchTrueFalseTotal
if (pCmdHead && pCmdHead -> nSwitchCodeType == 2) 0 0 0
if (pCmdHead && pCmdHead -> nSwitchCodeType == 2) 0 0 0
1546 {
1547 0 r -> Component.pProg = &r -> Component.pProgRun ;
1548 0 nCheckpointArrayOffset = 0 ;
1549 0 nCheckpointCodeOffset = 0 ;
1550 }
1551  
1552  
1553 0 return ok ;
1554 }
1555  
1556  
1557  
1558 /* ------------------------------------------------------------------------ */
1559 /* */
1560 /* embperl_CompileDomTree */
1561 /* */
1562 /* Compile root node and his children */
1563 /* */
1564 /* ------------------------------------------------------------------------ */
1565  
1566  
1567 0 static int embperl_CompileDomTree (/*in*/ tReq * r,
1568 /*in*/ tDomTree * pDomTree)
1569  
1570  
1571  
1572 {
1573 int rc ;
1574 0 int bCheckpointPending = 0 ;
1575 0 tIndex xDomTree = pDomTree -> xNdx ;
1576  
1577  
1578 0 pDomTree -> xCurrNode = 0 ;
1579  
1580 0 ▶ if ((rc = embperl_CompileNode (r, pDomTree, pDomTree -> xDocument, &bCheckpointPending)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = embperl_CompileNode (r, pDomTree, pDomTree -> xDocument, &bCheckpointPending)) != ok) 0 0 0
1581 0 return rc ;
1582  
1583 0 pDomTree = DomTree_self (xDomTree) ; /* addr may have changed */
1584  
1585 0 ▶ if (bCheckpointPending)
Branch: 1 branch
BranchTrueFalseTotal
if (bCheckpointPending) 0 0 0
1586 {
1587 int l ;
1588 char buf [80] ;
1589  
1590 0 int nCheckpointArrayOffset = ArrayAdd (r -> pApp, &pDomTree -> pCheckpoints, 1) ;
1591 0 pDomTree -> pCheckpoints[nCheckpointArrayOffset].xNode = -1 ;
1592 0 l = sprintf (buf, " _ep_cp(%d) ;\n", nCheckpointArrayOffset) ;
1593 0 StringAdd (r -> pApp, r -> Component.pProg, buf, l) ;
1594  
1595 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1596 0 lprintf (r -> pApp, "[%d]EPCOMP: #%d Checkpoint\n", r -> pThread -> nPid, -1) ;
1597  
1598 }
1599
1600 0 return ok ;
1601 }
1602  
1603  
1604  
1605 /* ------------------------------------------------------------------------ */
1606 /* */
1607 /* embperl_Compile */
1608 /* */
1609 /* Compile the whole document */
1610 /* */
1611 /* ------------------------------------------------------------------------ */
1612  
1613 0 int embperl_Compile (/*in*/ tReq * r,
1614 /*in*/ tIndex xDomTree,
1615 /*out*/ tIndex * pxResultDomTree,
1616 /*out*/ SV * * pProg)
1617  
1618  
1619 {
1620 epTHX_
1621 int rc ;
1622 0 tDomTree * pDomTree = DomTree_self (*pxResultDomTree = xDomTree) ;
1623 0 char * sSourcefile = DomTree_selfFilename (pDomTree) ;
1624 0 clock_t cl1 = clock () ;
1625 clock_t cl2 ;
1626 clock_t cl3 ;
1627 clock_t cl4 ;
1628 STRLEN l ;
1629 SV * pSV ;
1630 SV * args[2] ;
1631 /*
1632 int nStep = r -> Buf.pFile -> nFilesize / 4 ;
1633 if (nStep < 1024)
1634 nStep = 1024 ;
1635 else if (nStep > 4096)
1636 nStep = 4096 ;
1637 */
1638 0 int nStep = 8192 ;
1639 0 char *use_utf8 = "" ;
1640  
1641 0 ▶ if (strcmp (r -> Component.Config.sInputCharset, "utf8") == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp (r -> Component.Config.sInputCharset, "utf8") == 0) 0 0 0
1642 0 use_utf8 = "use utf8;" ;
1643  
1644 0 ▶ if (r -> Component.Config.bDebug & dbgCompile)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCompile) 0 0 0
1645 0 lprintf (r -> pApp, "[%d]EPCOMP: Start compiling %s DomTree = %d\n", r -> pThread -> nPid, sSourcefile, xDomTree) ;
1646  
1647 0 ▶ if (r -> Component.Config.bOptions & optChdirToSource)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bOptions & optChdirToSource) 0 0 0
1648 0 ChdirToSource (r, sSourcefile) ;
1649  
1650 0 r -> Component.nPhase = phCompile ;
1651  
1652 0 r -> Component.pProgRun = NULL ;
1653 0 r -> Component.pProgDef = NULL ;
1654  
1655 0 StringNew (r -> pApp, &r -> Component.pProgRun, nStep ) ;
1656 0 StringNew (r -> pApp, &r -> Component.pProgDef, nStep ) ;
1657 0 r -> Component.pProg = &r -> Component.pProgRun ;
1658  
1659 0 pDomTree -> pSV = (SV *)newHV () ;
1660 0 ▶ if (pDomTree -> pCheckpoints)
Branch: 1 branch
BranchTrueFalseTotal
if (pDomTree -> pCheckpoints) 0 0 0
1661 0 ArraySetSize (r -> pApp, &pDomTree -> pCheckpoints, 0) ;
1662 else
1663 0 ArrayNew (r -> pApp, &pDomTree -> pCheckpoints, 256, sizeof (tDomTreeCheckpoint)) ;
1664 0 ArrayAdd (r -> pApp, &pDomTree -> pCheckpoints, 1) ;
1665 0 pDomTree -> pCheckpoints[0].xNode = 0 ;
1666  
1667 0 ▶ if ((rc = embperl_CompileDomTree (r, pDomTree)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = embperl_CompileDomTree (r, pDomTree)) != ok) 0 0 0
1668 {
1669 /*
1670 *ppSV = newSVpvf ("%s\t%s", r -> errdat1, r -> errdat2) ;
1671 SvUPGRADE (*ppSV, SVt_PVIV) ;
1672 SvIVX (*ppSV) = rc ;
1673 if (r -> Component.xCurrDomTree)
1674 {
1675 DomTree_delete(DomTree_self(r -> Component.xCurrDomTree)) ;
1676 r -> Component.xCurrDomTree = 0 ;
1677 }
1678 */
1679 0 StringFree (r -> pApp, &r -> Component.pProgRun) ;
1680 0 StringFree (r -> pApp, &r -> Component.pProgDef) ;
1681 0 ArrayFree (r -> pApp, &pDomTree -> pCheckpoints) ;
1682 0 pDomTree -> pCheckpoints = NULL ;
1683  
1684 0 pDomTree = DomTree_self (xDomTree) ;
1685 0 DomTree_delete (r -> pApp, pDomTree) ;
1686 0 *pxResultDomTree = 0 ;
1687  
1688 0 return rc ;
1689 }
1690  
1691 0 pDomTree = DomTree_self (xDomTree) ; /* addr may have changed */
1692  
1693 0 SvREFCNT_dec (pDomTree -> pSV) ;
1694 0 pDomTree -> pSV = NULL ;
1695  
1696 0 StringAdd (r -> pApp, &r -> Component.pProgRun, "", 1) ;
1697 0 ▶ StringAdd (r -> pApp, &r -> Component.pProgDef, r -> Component.Config.sTopInclude?r -> Component.Config.sTopInclude:"", 0) ;
Branch: 1 branch
BranchTrueFalseTotal
StringAdd (r -> pApp, &r -> Component.pProgDef, r -> Component.Config.sTopInclude?r -> Component.Config.sTopInclude:"", 0) ; 0 0 0
1698  
1699 0 cl2 = clock () ;
1700  
1701 0 r -> Component.nPhase = phRunAfterCompile ;
1702
1703 0 l = ArrayGetSize (r -> pApp, r -> Component.pProgDef) ;
1704 0 ▶ if (l > 1 && r -> Component.Config.bDebug & dbgCompile)
Branch: 2 branches
BranchTrueFalseTotal
if (l > 1 && r -> Component.Config.bDebug & dbgCompile) 0 0 0
if (l > 1 && r -> Component.Config.bDebug & dbgCompile) 0 0 0
1705 0 lprintf (r -> pApp, "[%d]EPCOMP: AfterCompileTimeCode: %*.*s\n", r -> pThread -> nPid, l, l, r -> Component.pProgDef) ;
1706  
1707 0 ▶ if (l > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (l > 1) 0 0 0
1708 {
1709 0 pSV = newSVpvf("package %s ; %s\n%*.*s", r -> Component.sEvalPackage, use_utf8, (int)l,(int)l, r -> Component.pProgDef) ;
1710 newSVpvf2(pSV) ;
1711 0 args[0] = r -> _perlsv ;
1712 0 args[1] = pDomTree -> pDomTreeSV ;
1713 0 ▶ if ((rc = EvalDirect (r, pSV, 0, args)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = EvalDirect (r, pSV, 0, args)) != ok) 0 0 0
1714 0 LogError (r, rc) ;
1715 0 SvREFCNT_dec(pSV);
1716 }
1717  
1718 0 cl3 = clock () ;
1719
1720 0 r -> Component.nPhase = phPerlCompile ;
1721  
1722 0 ▶ if (PERLDB_LINE)
Branch: 1 branch
BranchTrueFalseTotal
if (PERLDB_LINE) 0 0 0
1723 { /* feed source to file gv (@/%_<filename) if we are running under the debugger */
1724 0 GV * pGVFile = gv_fetchfile (sSourcefile) ;
1725 0 AV * pDebugArray = GvAV (pGVFile) ;
1726  
1727
1728 0 char * p = r -> Component.pBuf ;
1729 char * end ;
1730 0 I32 i = 1 ;
1731 0 ▶ while (*p)
Branch: 1 branch
BranchTrueFalseTotal
while (*p) 0 0 0
1732 {
1733 0 end = strchr (p, '\n') ;
1734 0 ▶ if (end)
Branch: 1 branch
BranchTrueFalseTotal
if (end) 0 0 0
1735 {
1736 SV * pLine ;
1737 0 pLine = newSVpv (p, end - p + 1) ;
1738 0 ▶ SvUPGRADE (pLine, SVt_PVMG) ;
Branch: 1 branch
BranchTrueFalseTotal
SvUPGRADE (pLine, SVt_PVMG) ; 0 0 0
1739 0 av_store (pDebugArray, i++, pLine) ;
1740 0 p = end + 1 ;
1741 }
1742 0 ▶ else if (p < r -> Component.pEndPos)
Branch: 1 branch
BranchTrueFalseTotal
else if (p < r -> Component.pEndPos) 0 0 0
1743 {
1744 SV * pLine ;
1745 0 pLine = newSVpv (p, r -> Component.pEndPos - p + 1) ;
1746 0 ▶ SvUPGRADE (pLine, SVt_PVMG) ;
Branch: 1 branch
BranchTrueFalseTotal
SvUPGRADE (pLine, SVt_PVMG) ; 0 0 0
1747 0 av_store (pDebugArray, i++, pLine) ;
1748 0 break ;
1749 }
1750 }
1751 0 ▶ if (r -> Component.Config.bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug) 0 0 0
1752 0 lprintf (r -> pApp, "Setup source code for interactive debugger\n") ;
1753 }
1754
1755 /*
1756 * Does not work with perl >= 5.14
1757 */
1758 #if PERL_VERSION < 14
1759 UndefSub (r, r -> Component.sMainSub, r -> Component.sCurrPackage) ;
1760 #endif
1761  
1762 0 rc = EvalOnly (r, r -> Component.pProgRun, pProg, G_SCALAR, r -> Component.sMainSub) ;
1763
1764 0 StringFree (r -> pApp, &r -> Component.pProgRun) ;
1765 0 StringFree (r -> pApp, &r -> Component.pProgDef) ;
1766  
1767 0 ▶ if (rc != ok && xDomTree)
Branch: 2 branches
BranchTrueFalseTotal
if (rc != ok && xDomTree) 0 0 0
if (rc != ok && xDomTree) 0 0 0
1768 {
1769 0 pDomTree = DomTree_self (xDomTree) ;
1770 0 ▶ if (pDomTree)
Branch: 1 branch
BranchTrueFalseTotal
if (pDomTree) 0 0 0
1771 0 DomTree_delete (r -> pApp, pDomTree) ;
1772 0 *pxResultDomTree = 0 ;
1773 }
1774  
1775 0 cl4 = clock () ;
1776  
1777 #ifdef CLOCKS_PER_SEC
1778 0 ▶ if (r -> Component.Config.bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug) 0 0 0
1779 {
1780 0 lprintf (r -> pApp, "[%d]PERF: Compile Start Time: %d ms \n", r -> pThread -> nPid, ((cl1 - r -> startclock) * 1000 / CLOCKS_PER_SEC)) ;
1781 0 lprintf (r -> pApp, "[%d]PERF: Compile End Time: %d ms \n", r -> pThread -> nPid, ((cl2 - r -> startclock) * 1000 / CLOCKS_PER_SEC)) ;
1782 0 lprintf (r -> pApp, "[%d]PERF: After Compile Exec End Time: %d ms \n", r -> pThread -> nPid, ((cl3 - r -> startclock) * 1000 / CLOCKS_PER_SEC)) ;
1783 0 lprintf (r -> pApp, "[%d]PERF: Perl Compile End Time: %d ms \n", r -> pThread -> nPid, ((cl4 - r -> startclock) * 1000 / CLOCKS_PER_SEC)) ;
1784 0 lprintf (r -> pApp, "[%d]PERF: Compile Time: %d ms \n", r -> pThread -> nPid, ((cl4 - cl1) * 1000 / CLOCKS_PER_SEC)) ;
1785 0 DomStats (r -> pApp) ;
1786 }
1787 #endif
1788  
1789 0 return rc ;
1790 }
1791  
1792  
1793 /* ------------------------------------------------------------------------ */
1794 /* */
1795 /* embperl_Executer */
1796 /* */
1797 /* ------------------------------------------------------------------------ */
1798  
1799 0 static int embperl_Execute2 (/*in*/ tReq * r,
1800 /*in*/ tIndex xSrcDomTree,
1801 /*in*/ CV * pCV,
1802 /*in*/ tIndex * pResultDomTree)
1803  
1804  
1805 {
1806 epTHX_
1807 int rc ;
1808 tDomTree * pCurrDomTree ;
1809 0 clock_t cl1 = clock () ;
1810 clock_t cl2 ;
1811 SV * pSV ;
1812 char * sSubName ;
1813  
1814 0 tainted = 0 ;
1815 0 r -> Component.xCurrDomTree = xSrcDomTree ;
1816  
1817 0 sSubName = r -> Component.Param.sSub ;
1818  
1819 0 ▶ if (sSubName && !*sSubName)
Branch: 2 branches
BranchTrueFalseTotal
if (sSubName && !*sSubName) 0 0 0
if (sSubName && !*sSubName) 0 0 0
1820 0 sSubName = NULL ;
1821 0 rc = ok ;
1822 0 cl1 = clock () ;
1823
1824  
1825 0 r -> Component.nPhase = phRun ;
1826  
1827
1828 0 r -> Component.nCurrCheckpoint = 1 ;
1829 0 r -> Component.nCurrRepeatLevel = 0 ;
1830 0 r -> Component.xSourceDomTree = r -> Component.xCurrDomTree ;
1831 0 ▶ if (!(r -> Component.xCurrDomTree = DomTree_clone (r -> pApp, DomTree_self (xSrcDomTree), &pCurrDomTree, sSubName?1:0)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(r -> Component.xCurrDomTree = DomTree_clone (r -> pApp, DomTree_self (xSrcDomTree), &pCurrDomTree, sSubName?1:0))) 0 0 0
1832 0 return 1 ;
1833  
1834 0 *pResultDomTree = r -> Component.xCurrDomTree ;
1835 /* -> is done by cache management -> av_push (r -> pDomTreeAV, pCurrDomTree -> pDomTreeSV) ; */
1836 0 pCurrDomTree = DomTree_self (r -> Component.xCurrDomTree) ;
1837 0 ArrayNewZero (r -> pApp, &pCurrDomTree -> pCheckpointStatus, ArrayGetSize (r -> pApp, pCurrDomTree -> pCheckpoints), sizeof(tDomTreeCheckpointStatus)) ;
1838  
1839 0 ▶ if (pCV)
Branch: 1 branch
BranchTrueFalseTotal
if (pCV) 0 0 0
1840 {
1841 SV * args[2] ;
1842 STRLEN l ;
1843 0 SV * sDomTreeSV = newSVpvf ("%s::%s", r -> Component.sEvalPackage, "_ep_DomTree") ;
1844 0 SV * pDomTreeSV = perl_get_sv (SvPV (sDomTreeSV, l), TRUE) ;
1845 0 IV xOldDomTree = 0 ;
1846 newSVpvf2(sDomTreeSV) ;
1847
1848 0 ▶ if (SvIOK (pDomTreeSV))
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK (pDomTreeSV)) 0 0 0
1849 0 xOldDomTree = SvIVX (pDomTreeSV) ;
1850  
1851 0 sv_setiv (pDomTreeSV, r -> Component.xCurrDomTree) ;
1852 0 SvREFCNT_dec (sDomTreeSV) ;
1853  
1854 0 av_push (r -> pCleanupAV, newRV_inc (pDomTreeSV)) ;
1855
1856 0 args[0] = r -> _perlsv ;
1857 0 ▶ if (sSubName)
Branch: 1 branch
BranchTrueFalseTotal
if (sSubName) 0 0 0
1858 {
1859 0 SV * pSVName = newSVpvf ("%s::_ep_sub_%s", r -> Component.sEvalPackage, sSubName) ;
1860 newSVpvf2(pSVName) ;
1861 0 pCurrDomTree -> xDocument = 0 ; /* set by first checkpoint */
1862 0 rc = CallStoredCV (r, r -> Component.pProgRun, (CV *)pSVName, 1, args, 0, &pSV) ;
1863 0 ▶ if (pSVName)
Branch: 1 branch
BranchTrueFalseTotal
if (pSVName) 0 0 0
1864 0 SvREFCNT_dec (pSVName) ;
1865 0 ▶ if (pSV)
Branch: 1 branch
BranchTrueFalseTotal
if (pSV) 0 0 0
1866 0 SvREFCNT_dec (pSV) ;
1867 }
1868 else
1869 {
1870 0 rc = CallStoredCV (r, r -> Component.pProgRun, (CV *)pCV, 1, args, 0, &pSV) ;
1871 0 ▶ if (pSV)
Branch: 1 branch
BranchTrueFalseTotal
if (pSV) 0 0 0
1872 0 SvREFCNT_dec (pSV) ;
1873 }
1874  
1875 0 pCurrDomTree = DomTree_self (r -> Component.xCurrDomTree) ; /* relookup DomTree in case it has moved */
1876 0 cl2 = clock () ;
1877 #ifdef CLOCKS_PER_SEC
1878 0 ▶ if (r -> Component.Config.bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug) 0 0 0
1879 {
1880 0 lprintf (r -> pApp, "[%d]PERF: Run Start Time: %d ms \n", r -> pThread -> nPid, ((cl1 - r -> startclock) * 1000 / CLOCKS_PER_SEC)) ;
1881 0 lprintf (r -> pApp, "[%d]PERF: Run End Time: %d ms \n", r -> pThread -> nPid, ((cl2 - r -> startclock) * 1000 / CLOCKS_PER_SEC)) ;
1882 0 lprintf (r -> pApp, "[%d]PERF: Run Time: %d ms \n", r -> pThread -> nPid, ((cl2 - cl1) * 1000 / CLOCKS_PER_SEC)) ;
1883 0 DomStats (r -> pApp) ;
1884 }
1885 #endif
1886  
1887 0 sv_setiv (pDomTreeSV, xOldDomTree) ;
1888 }
1889  
1890 0 ArrayFree (r -> pApp, &pCurrDomTree -> pCheckpointStatus) ;
1891  
1892 0 ▶ if (rc != ok && rc != rcEvalErr)
Branch: 2 branches
BranchTrueFalseTotal
if (rc != ok && rc != rcEvalErr) 0 0 0
if (rc != ok && rc != rcEvalErr) 0 0 0
1893 0 return rc ;
1894  
1895 0 r -> Component.nPhase = phTerm ;
1896
1897 0 return ok ;
1898 }
1899  
1900 /* ------------------------------------------------------------------------ */
1901 /* */
1902 /* embperl_Execute */
1903 /* */
1904 /* ------------------------------------------------------------------------ */
1905  
1906 0 int embperl_Execute (/*in*/ tReq * r,
1907 /*in*/ tIndex xSrcDomTree,
1908 /*in*/ CV * pCV,
1909 /*in*/ tIndex * pResultDomTree)
1910  
1911  
1912 {
1913 epTHX_
1914 0 int rc = ok ;
1915 0 char * sSourcefile = r -> Component.sSourcefile ;
1916
1917 0 tainted = 0 ;
1918  
1919 0 ▶ if (!r -> bError)
Branch: 1 branch
BranchTrueFalseTotal
if (!r -> bError) 0 0 0
1920 {
1921 0 tComponent * c = &r -> Component ;
1922 GV * gv ;
1923 0 HV * pStash = gv_stashpv (c -> sCurrPackage, 1) ;
1924  
1925
1926 0 ▶ if (r -> Component.Config.nCleanup > -1 && (r -> Component.Config.bOptions & optDisableVarCleanup) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (r -> Component.Config.nCleanup > -1 && (r -> Component.Config.bOptions & optDisableVarCleanup) == 0) 0 0 0
if (r -> Component.Config.nCleanup > -1 && (r -> Component.Config.bOptions & optDisableVarCleanup) == 0) 0 0 0
1927 0 SetHashValueInt (r, r -> pCleanupPackagesHV, r -> Component.sCurrPackage, 1) ;
1928
1929 /* --- change working directory --- */
1930 0 ▶ if (r -> Component.Config.bOptions & optChdirToSource)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bOptions & optChdirToSource) 0 0 0
1931 0 ChdirToSource (r, sSourcefile) ;
1932  
1933  
1934 0 ▶ if (c -> Param.pParam)
Branch: 1 branch
BranchTrueFalseTotal
if (c -> Param.pParam) 0 0 0
1935 {
1936 0 gv = *((GV **)hv_fetch (pStash, "param", 5, 0)) ;
1937 /* gv = r -> pThread -> pParamArrayGV ; */
1938 0 save_ary (gv) ;
1939 0 SvREFCNT_dec((SV *)GvAV(gv)) ;
1940 0 GvAV(gv) = (AV *)SvREFCNT_inc(c -> Param.pParam) ;
1941 }
1942
1943 0 ▶ if (c -> Param.pFormHash)
Branch: 1 branch
BranchTrueFalseTotal
if (c -> Param.pFormHash) 0 0 0
1944 {
1945 0 gv = *((GV **)hv_fetch (pStash, "fdat", 4, 0)) ;
1946 /* gv = r -> pThread -> pFormHashGV ; */
1947 0 save_hash (gv) ;
1948 0 SvREFCNT_dec((SV *)GvHV(gv)) ;
1949 0 GvHV(gv) = (HV *)SvREFCNT_inc(c -> Param.pFormHash) ;
1950 }
1951  
1952 0 ▶ if (c -> Param.pFormArray || c -> Param.pFormHash)
Branch: 2 branches
BranchTrueFalseTotal
if (c -> Param.pFormArray || c -> Param.pFormHash) 0 0 0
if (c -> Param.pFormArray || c -> Param.pFormHash) 0 0 0
1953 {
1954 0 gv = *((GV **)hv_fetch (pStash, "ffld", 4, 0)) ;
1955 /* gv = r -> pThread -> pFormArrayGV ; */
1956 0 save_ary (gv) ;
1957 0 SvREFCNT_dec((SV *)GvAV(gv)) ;
1958 0 ▶ if (c -> Param.pFormArray)
Branch: 1 branch
BranchTrueFalseTotal
if (c -> Param.pFormArray) 0 0 0
1959 0 GvAV(gv) = (AV *)SvREFCNT_inc(c -> Param.pFormArray) ;
1960 else
1961 {
1962 /* SVREFCNT_dec (pAV) is done by LEAVE, because of save_ary above (you can savely ignore dmalloc logged error) */
1963 0 AV * pAV = newAV ();
1964 HE * pEntry ;
1965 char * pKey ;
1966 I32 l ;
1967 0 GvAV(gv) = pAV ;
1968 0 hv_iterinit (c -> Param.pFormHash) ;
1969 0 ▶ while ((pEntry = hv_iternext (c -> Param.pFormHash)))
Branch: 1 branch
BranchTrueFalseTotal
while ((pEntry = hv_iternext (c -> Param.pFormHash))) 0 0 0
1970 {
1971 0 pKey = hv_iterkey (pEntry, &l) ;
1972 0 av_push (pAV, newSVpv(pKey, l)) ;
1973 }
1974 }
1975
1976 }
1977 else
1978 {
1979
1980  
1981  
1982 }
1983
1984 0 rc = embperl_Execute2 (r, xSrcDomTree, pCV, pResultDomTree) ;
1985  
1986  
1987 /* --- restore working directory --- */
1988 0 ▶ if (r -> Component.sResetDir[0])
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.sResetDir[0]) 0 0 0
1989 {
1990 #ifdef WIN32
1991 _chdrive (r -> Component.nResetDrive) ;
1992 #endif
1993 0 chdir (r -> Component.sResetDir) ;
1994 0 strcpy (r -> Component.sCWD,r -> Component.sResetDir) ;
1995 0 r -> Component.sResetDir[0] = '\0' ;
1996 }
1997 }
1998 else
1999 0 *pResultDomTree = 0 ;
2000  
2001 0 r -> Component.nPhase = phTerm ;
2002
2003 0 return rc ;
2004 }
2005  
2006  
2007  
2008 /* ------------------------------------------------------------------------ */
2009 /* */
2010 /* embperl_ExecuteSubStart */
2011 /* */
2012 /* Setup the start of a sub */
2013 /* */
2014 /* in pDomTreeSV SV which holds the DomTree in the current package */
2015 /* in xDomTree Source DomTree */
2016 /* in pSaveAV Array to save some values */
2017 /* */
2018 /* ------------------------------------------------------------------------ */
2019  
2020  
2021 0 int embperl_ExecuteSubStart (/*in*/ tReq * r,
2022 /*in*/ SV * pDomTreeSV,
2023 /*in*/ tIndex xDomTree,
2024 /*in*/ AV * pSaveAV)
2025  
2026 {
2027 epTHX_
2028 0 tIndex xOrgDomTree = -1 ;
2029 tIndex xOldDomTree ;
2030 tDomTree * pDomTree ;
2031 tDomTree * pCurrDomTree ;
2032  
2033 0 ▶ if (!r || !r -> Component.bReqRunning)
Branch: 2 branches
BranchTrueFalseTotal
if (!r || !r -> Component.bReqRunning) 0 0 0
if (!r || !r -> Component.bReqRunning) 0 0 0
2034 {
2035 0 ▶ LogErrorParam (r?r -> pApp:NULL, rcSubCallNotRequest, "", "") ;
Branch: 1 branch
BranchTrueFalseTotal
LogErrorParam (r?r -> pApp:NULL, rcSubCallNotRequest, "", "") ; 0 0 0
2036 0 return rcSubCallNotRequest ;
2037 }
2038  
2039 0 av_push (pSaveAV, newSViv (r -> Component.xCurrDomTree)) ;
2040 0 av_push (pSaveAV, newSViv (r -> Component.xCurrNode)) ;
2041 0 av_push (pSaveAV, newSViv (r -> Component.nCurrRepeatLevel)) ;
2042 0 av_push (pSaveAV, newSViv (r -> Component.nCurrCheckpoint)) ;
2043 0 av_push (pSaveAV, newSViv (r -> Component.bSubNotEmpty)) ;
2044  
2045 0 pDomTree = DomTree_self (xDomTree) ;
2046  
2047 0 xOldDomTree = r -> Component.xCurrDomTree ;
2048  
2049 0 ▶ if (!(r -> Component.xCurrDomTree = DomTree_clone (r -> pApp, pDomTree, &pCurrDomTree, 1)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(r -> Component.xCurrDomTree = DomTree_clone (r -> pApp, pDomTree, &pCurrDomTree, 1))) 0 0 0
2050 0 return 0 ;
2051 0 ArrayNewZero (r -> pApp, &pCurrDomTree -> pCheckpointStatus, ArrayGetSize (r -> pApp, pCurrDomTree -> pCheckpoints), sizeof(tDomTreeCheckpointStatus)) ;
2052 0 r -> Component.nCurrCheckpoint = 1 ;
2053 0 r -> Component.nCurrRepeatLevel = 0 ;
2054 0 r -> Component.xCurrNode = 0 ;
2055 0 r -> Component.bSubNotEmpty = 0 ;
2056 0 pCurrDomTree -> xDocument = 0 ; /* set by first checkpoint */
2057
2058 0 av_push (r -> pDomTreeAV, pCurrDomTree -> pDomTreeSV) ;
2059 0 av_push (r -> pCleanupAV, newRV_inc (pDomTreeSV)) ;
2060  
2061 0 sv_setiv (pDomTreeSV, r -> Component.xCurrDomTree) ;
2062  
2063 0 ▶ if (r -> Component.Config.bDebug & dbgRun)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgRun) 0 0 0
2064 0 lprintf (r -> pApp, "[%d]SUB: Enter from DomTree=%d into new DomTree=%d, Source DomTree=%d (org=%d)\n", r -> pThread -> nPid, xOldDomTree, r -> Component.xCurrDomTree, xDomTree, xOrgDomTree) ;
2065  
2066 0 return r -> Component.xCurrDomTree ;
2067 }
2068  
2069 /* ------------------------------------------------------------------------ */
2070 /* */
2071 /* embperl_ExecuteSubEnd */
2072 /* */
2073 /* End a sub */
2074 /* */
2075 /* in pSaveAV Array to save some values */
2076 /* */
2077 /* ------------------------------------------------------------------------ */
2078  
2079  
2080 0 int embperl_ExecuteSubEnd (/*in*/ tReq * r,
2081 /*in*/ SV * pDomTreeSV,
2082 /*in*/ AV * pSaveAV)
2083  
2084 {
2085 epTHX_
2086 0 tIndex xSubDomTree = r -> Component.xCurrDomTree ;
2087 tIndex xDocFraq ;
2088 0 int bSubNotEmpty = r -> Component.bSubNotEmpty ;
2089 tDomTree * pCallerDomTree ;
2090 0 tDomTree * pSubDomTree = DomTree_self (xSubDomTree) ;
2091  
2092 0 ▶ if (AvFILL (pSaveAV) < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (AvFILL (pSaveAV) < 1) 0 0 0
2093 0 return ok ;
2094
2095 0 ▶ if (r -> Component.xCurrNode == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.xCurrNode == 0) 0 0 0
2096 0 bSubNotEmpty = 1 ;
2097  
2098 0 ArrayFree (r -> pApp, &pSubDomTree -> pCheckpointStatus) ;
2099  
2100 0 r -> Component.xCurrDomTree = SvIV (* av_fetch (pSaveAV, 0, 0)) ;
2101 0 r -> Component.xCurrNode = SvIV (* av_fetch (pSaveAV, 1, 0)) ;
2102 0 r -> Component.nCurrRepeatLevel = (tRepeatLevel)SvIV (* av_fetch (pSaveAV, 2, 0)) ;
2103 0 r -> Component.nCurrCheckpoint = SvIV (* av_fetch (pSaveAV, 3, 0)) ;
2104 0 r -> Component.bSubNotEmpty = SvIV (* av_fetch (pSaveAV, 4, 0)) + bSubNotEmpty;
2105  
2106 0 sv_setiv (pDomTreeSV, r -> Component.xCurrDomTree) ;
2107 0 pCallerDomTree = DomTree_self (r -> Component.xCurrDomTree) ;
2108  
2109 0 ▶ if (bSubNotEmpty && r -> Component.xCurrNode)
Branch: 2 branches
BranchTrueFalseTotal
if (bSubNotEmpty && r -> Component.xCurrNode) 0 0 0
if (bSubNotEmpty && r -> Component.xCurrNode) 0 0 0
2110 0 r -> Component.xCurrNode = xDocFraq = Node_insertAfter (r -> pApp, pSubDomTree, pSubDomTree -> xDocument, 0, pCallerDomTree, r -> Component.xCurrNode, r -> Component.nCurrRepeatLevel) ;
2111  
2112 0 ▶ if (r -> Component.Config.bDebug & dbgRun)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgRun) 0 0 0
2113 0 lprintf (r -> pApp, "[%d]SUB: Leave from DomTree=%d back to DomTree=%d RepeatLevel=%d\n", r -> pThread -> nPid, xSubDomTree, r -> Component.xCurrDomTree, r -> Component.nCurrRepeatLevel) ;
2114  
2115 0 return ok ;
2116 }
2117  
« epcmd2.c ↑ Summary epdefault.c »