Expr.xs

filter: Statementstmt 93.7% 60 / 64 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 87.8% 72 / 82 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/lib/Cond/Expr.pm »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "callchecker0.h"
4 #include "callparser.h"
5 #include "XSUB.h"
6 #include "ppport.h"
7  
8 #define DEMAND_IMMEDIATE 0x00000001
9 #define DEMAND_NOCONSUME 0x00000002
10 #define demand_unichar(c, f) THX_demand_unichar(aTHX_ c, f)
11 static void
12 17 THX_demand_unichar (pTHX_ I32 c, U32 flags)
13 {
14 17 ▶ if (!(flags & DEMAND_IMMEDIATE))
Branch: 1 branch
BranchTrueFalseTotal
if (!(flags & DEMAND_IMMEDIATE)) 17 0 17
15 17 lex_read_space(0);
16  
17 17 ▶ if (lex_peek_unichar(0) != c)
Branch: 1 branch
BranchTrueFalseTotal
if (lex_peek_unichar(0) != c) 0 17 17
18 0 croak("syntax error");
19  
20 17 ▶ if (!(flags & DEMAND_NOCONSUME))
Branch: 1 branch
BranchTrueFalseTotal
if (!(flags & DEMAND_NOCONSUME)) 10 7 17
21 10 lex_read_unichar(0);
22 17 }
23  
24 #define parse_idword(word) THX_parse_idword(aTHX_ word)
25 static bool
26 2 THX_parse_idword(pTHX_ char const *word)
27 {
28 char *start, *s, c;
29  
30 2 s = start = PL_parser->bufptr;
31 2 c = *s;
32  
33 2 ▶ if (!isIDFIRST(c))
Branch: 1 branch
BranchTrueFalseTotal
if (!isIDFIRST(c)) 0 2 2
34 0 return 0;
35  
36 do {
37 18 c = *++s;
38 18 ▶ } while (isALNUM(c));
Branch: 1 branch
BranchTrueFalseTotal
} while (isALNUM(c)); 16 2 18
39  
40 2 ▶ if (strnNE(word, start, s-start))
Branch: 1 branch
BranchTrueFalseTotal
if (strnNE(word, start, s-start)) 0 2 2
41 0 return 0;
42  
43 2 lex_read_to(s);
44 2 return 1;
45 }
46  
47 #define parse_blk() THX_parse_blk(aTHX)
48 static OP *
49 7 THX_parse_blk(pTHX)
50 {
51 int blk_floor;
52 OP *blkop;
53  
54 7 demand_unichar('{', DEMAND_NOCONSUME);
55 7 blk_floor = Perl_block_start(aTHX_ 1);
56 7 blkop = parse_block(0);
57 7 return op_scope(Perl_block_end(aTHX_ blk_floor, blkop));
58 }
59  
60 static OP *
61 5 myck_entersub_cond (pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
62 {
63 OP *pushop, *condop, *rv2cvop;
64 5 OP *parent = entersubop;
65  
66 PERL_UNUSED_ARG(namegv);
67 PERL_UNUSED_ARG(ckobj);
68  
69 5 pushop = cUNOPx(entersubop)->op_first;
70 5 ▶ if (!OpHAS_SIBLING(pushop)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!OpHAS_SIBLING(pushop)) { 5 0 5
71 5 parent = pushop;
72 5 pushop = cUNOPx(pushop)->op_first;
73 }
74  
75 #ifdef op_sibling_splice
76 5 condop = op_sibling_splice(parent, pushop, 1, NULL);
77 #else
78 condop = pushop->op_sibling;
79 rv2cvop = condop->op_sibling;
80 condop->op_sibling = NULL;
81 pushop->op_sibling = rv2cvop;
82 #endif
83  
84 5 op_free(entersubop);
85 5 return condop;
86 }
87  
88 static OP *
89 5 myparse_args_cond (pTHX_ GV *namegv, SV *psobj, U32 *flagsp)
90 {
91 AV *exprs, *blks;
92 OP *condop;
93  
94 PERL_UNUSED_ARG(namegv);
95 PERL_UNUSED_ARG(psobj);
96 PERL_UNUSED_ARG(flagsp);
97  
98 5 exprs = newAV();
99 5 blks = newAV();
100 5 AvREAL_off(exprs);
101 5 AvREAL_off(blks);
102  
103 while (1) {
104 12 lex_read_space(0);
105  
106 12 switch (lex_peek_unichar(0)) {
107 5 case '(':
108 5 demand_unichar('(', 0);
109 5 av_push(exprs, (SV *)parse_fullexpr(0));
110 5 demand_unichar(')', 0);
111  
112 5 av_push(blks, (SV *)parse_blk());
113 5 continue;
114 2 case 'o':
115 2 ▶ if (parse_idword("otherwise")) {
Branch: 1 branch
BranchTrueFalseTotal
if (parse_idword("otherwise")) { 2 0 2
116 2 av_push(exprs, (SV *)newSVOP(OP_CONST, 0, &PL_sv_yes));
117 2 av_push(blks, (SV *)parse_blk());
118 }
119 2 continue;
120 5 default:
121 5 break;
122 }
123  
124 5 break;
125 }
126  
127 5 condop = newOP(OP_STUB, 0);
128 12 ▶ while (av_len(exprs) >= 0)
Branch: 1 branch
BranchTrueFalseTotal
while (av_len(exprs) >= 0) 7 5 12
129 7 condop = newCONDOP(0,
130 (OP *)av_pop(exprs),
131 (OP *)av_pop(blks),
132 condop);
133  
134 5 SvREFCNT_inc(exprs);
135 5 SvREFCNT_inc(blks);
136  
137 5 return condop;
138 }
139  
140 MODULE = Cond::Expr PACKAGE = Cond::Expr
141  
142 void
143 cond (...)
144 CODE:
145 PERL_UNUSED_ARG(items);
146 0 croak("cond called as a function");
147  
148 BOOT:
149 {
150 CV *cond_cv;
151  
152 1 cond_cv = get_cv("Cond::Expr::cond", 0);
153  
154 1 cv_set_call_parser(cond_cv, myparse_args_cond, &PL_sv_undef);
155 1 cv_set_call_checker(cond_cv, myck_entersub_cond, &PL_sv_undef);
156 }
↑ Summary blib/lib/Cond/Expr.pm »