Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison directive.c @ 16:9dda765ee85c
expression evaluator
author | David A. Holland |
---|---|
date | Mon, 20 Dec 2010 00:32:20 -0500 (2010-12-20) |
parents | f6177d3ed5c2 |
children | c08a947d8f30 |
comparison
equal
deleted
inserted
replaced
15:f6177d3ed5c2 | 16:9dda765ee85c |
---|---|
9 #include "files.h" | 9 #include "files.h" |
10 #include "directive.h" | 10 #include "directive.h" |
11 #include "macro.h" | 11 #include "macro.h" |
12 #include "eval.h" | 12 #include "eval.h" |
13 | 13 |
14 static const char ws[] = " \t\f\v"; | |
15 | |
16 struct ifstate { | 14 struct ifstate { |
17 struct ifstate *prev; | 15 struct ifstate *prev; |
18 struct place startplace; | 16 struct place startplace; |
19 bool curtrue; | 17 bool curtrue; |
20 bool evertrue; | 18 bool evertrue; |
92 void | 90 void |
93 d_if(struct place *p, struct place *p2, char *line, size_t len) | 91 d_if(struct place *p, struct place *p2, char *line, size_t len) |
94 { | 92 { |
95 char *expr; | 93 char *expr; |
96 bool val; | 94 bool val; |
95 struct place p3 = *p2; | |
97 | 96 |
98 expr = macroexpand(p2, line, len, true); | 97 expr = macroexpand(p2, line, len, true); |
99 val = eval(expr); | 98 val = eval(&p3, expr); |
100 ifstate_push(p, val); | 99 ifstate_push(p, val); |
101 free(expr); | 100 free(expr); |
102 } | 101 } |
103 | 102 |
104 static | 103 static |
120 static | 119 static |
121 void | 120 void |
122 d_elif(struct place *p, struct place *p2, char *line, size_t len) | 121 d_elif(struct place *p, struct place *p2, char *line, size_t len) |
123 { | 122 { |
124 char *expr; | 123 char *expr; |
124 struct place p3 = *p2; | |
125 | 125 |
126 if (ifstate->seenelse) { | 126 if (ifstate->seenelse) { |
127 complain(p, "#elif after #else"); | 127 complain(p, "#elif after #else"); |
128 complain_fail(); | 128 complain_fail(); |
129 } | 129 } |
130 | 130 |
131 if (ifstate->evertrue) { | 131 if (ifstate->evertrue) { |
132 ifstate->curtrue = false; | 132 ifstate->curtrue = false; |
133 } else { | 133 } else { |
134 expr = macroexpand(p2, line, len, true); | 134 expr = macroexpand(p2, line, len, true); |
135 ifstate->curtrue = eval(expr); | 135 ifstate->curtrue = eval(&p3, expr); |
136 ifstate->evertrue = ifstate->curtrue; | 136 ifstate->evertrue = ifstate->curtrue; |
137 free(expr); | 137 free(expr); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |