annotate directive.c @ 154:a2c2fe8dbea3

Wrap up the current and next line position when invoking directives. (in preparation for implementing #line)
author David A. Holland
date Fri, 12 Jun 2015 00:56:12 -0400
parents 1cda505ddc78
children f14f5352956c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
1 /*-
99
60184aa42604 add 2013 to copyrights where it seems warranted
David A. Holland
parents: 90
diff changeset
2 * Copyright (c) 2010, 2013 The NetBSD Foundation, Inc.
30
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
3 * All rights reserved.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
4 *
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
5 * This code is derived from software contributed to The NetBSD Foundation
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
6 * by David A. Holland.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
7 *
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
8 * Redistribution and use in source and binary forms, with or without
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
9 * modification, are permitted provided that the following conditions
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
10 * are met:
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
11 * 1. Redistributions of source code must retain the above copyright
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
12 * notice, this list of conditions and the following disclaimer.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
13 * 2. Redistributions in binary form must reproduce the above copyright
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
14 * notice, this list of conditions and the following disclaimer in the
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
15 * documentation and/or other materials provided with the distribution.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
16 *
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
27 * POSSIBILITY OF SUCH DAMAGE.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
28 */
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
29
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
30 #include <assert.h>
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
31 #include <stdbool.h>
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
32 #include <stdlib.h>
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
33 #include <string.h>
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
34
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
35 #include "utils.h"
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
36 #include "mode.h"
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
37 #include "place.h"
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
38 #include "files.h"
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
39 #include "directive.h"
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
40 #include "macro.h"
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
41 #include "eval.h"
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
42 #include "output.h"
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
43
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
44 struct ifstate {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
45 struct ifstate *prev;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
46 struct place startplace;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
47 bool curtrue;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
48 bool evertrue;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
49 bool seenelse;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
50 };
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
51
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
52 static struct ifstate *ifstate;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
53
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
54 ////////////////////////////////////////////////////////////
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
55 // common parsing bits
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
56
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
57 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
58 void
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
59 uncomment(char *buf)
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
60 {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
61 char *s, *t, *u = NULL;
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
62 bool incomment = false;
81
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
63 bool inesc = false;
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
64 bool inquote = false;
128
1cda505ddc78 Don't expand macros within character constants.
David A. Holland
parents: 127
diff changeset
65 char quote = '\0';
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
66
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
67 for (s = t = buf; *s; s++) {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
68 if (incomment) {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
69 if (s[0] == '*' && s[1] == '/') {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
70 s++;
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
71 incomment = false;
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
72 }
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
73 } else {
81
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
74 if (!inquote && s[0] == '/' && s[1] == '*') {
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
75 incomment = true;
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
76 } else {
81
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
77 if (inesc) {
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
78 inesc = false;
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
79 } else if (s[0] == '\\') {
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
80 inesc = true;
128
1cda505ddc78 Don't expand macros within character constants.
David A. Holland
parents: 127
diff changeset
81 } else if (!inquote &&
1cda505ddc78 Don't expand macros within character constants.
David A. Holland
parents: 127
diff changeset
82 (s[0] == '"' || s[0] == '\'')) {
1cda505ddc78 Don't expand macros within character constants.
David A. Holland
parents: 127
diff changeset
83 inquote = true;
1cda505ddc78 Don't expand macros within character constants.
David A. Holland
parents: 127
diff changeset
84 quote = s[0];
1cda505ddc78 Don't expand macros within character constants.
David A. Holland
parents: 127
diff changeset
85 } else if (inquote && s[0] == quote) {
1cda505ddc78 Don't expand macros within character constants.
David A. Holland
parents: 127
diff changeset
86 inquote = false;
81
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
87 }
27c9aafcaca1 Don't recognize comments within double-quote strings.
David A. Holland
parents: 77
diff changeset
88
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
89 if (t != s) {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
90 *t = *s;
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
91 }
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
92 if (!strchr(ws, *t)) {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
93 u = t;
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
94 }
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
95 t++;
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
96 }
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
97 }
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
98 }
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
99 if (u) {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
100 /* end string after last non-whitespace char */
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
101 u[1] = '\0';
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
102 } else {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
103 *t = '\0';
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
104 }
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
105 }
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
106
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
107 static
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
108 void
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
109 oneword(const char *what, struct place *p2, char *line)
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
110 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
111 size_t pos;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
112
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
113 pos = strcspn(line, ws);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
114 if (line[pos] != '\0') {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
115 p2->column += pos;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
116 complain(p2, "Garbage after %s argument", what);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
117 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
118 line[pos] = '\0';
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
119 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
120 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
121
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
122 ////////////////////////////////////////////////////////////
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
123 // if handling
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
124
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
125 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
126 struct ifstate *
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
127 ifstate_create(struct ifstate *prev, struct place *p, bool startstate)
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
128 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
129 struct ifstate *is;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
130
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
131 is = domalloc(sizeof(*is));
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
132 is->prev = prev;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
133 if (p != NULL) {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
134 is->startplace = *p;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
135 } else {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
136 place_setbuiltin(&is->startplace, 1);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
137 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
138 is->curtrue = startstate;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
139 is->evertrue = is->curtrue;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
140 is->seenelse = false;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
141 return is;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
142 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
143
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
144 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
145 void
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
146 ifstate_destroy(struct ifstate *is)
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
147 {
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
148 dofree(is, sizeof(*is));
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
149 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
150
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
151 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
152 void
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
153 ifstate_push(struct place *p, bool startstate)
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
154 {
72
b1d0f10e8d36 handle nested ifs correctly
David A. Holland
parents: 66
diff changeset
155 struct ifstate *newstate;
b1d0f10e8d36 handle nested ifs correctly
David A. Holland
parents: 66
diff changeset
156
b1d0f10e8d36 handle nested ifs correctly
David A. Holland
parents: 66
diff changeset
157 newstate = ifstate_create(ifstate, p, startstate);
b1d0f10e8d36 handle nested ifs correctly
David A. Holland
parents: 66
diff changeset
158 if (!ifstate->curtrue) {
b1d0f10e8d36 handle nested ifs correctly
David A. Holland
parents: 66
diff changeset
159 newstate->curtrue = false;
b1d0f10e8d36 handle nested ifs correctly
David A. Holland
parents: 66
diff changeset
160 newstate->evertrue = true;
b1d0f10e8d36 handle nested ifs correctly
David A. Holland
parents: 66
diff changeset
161 }
b1d0f10e8d36 handle nested ifs correctly
David A. Holland
parents: 66
diff changeset
162 ifstate = newstate;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
163 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
164
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
165 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
166 void
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
167 ifstate_pop(void)
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
168 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
169 struct ifstate *is;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
170
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
171 is = ifstate;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
172 ifstate = ifstate->prev;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
173 ifstate_destroy(is);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
174 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
175
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
176 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
177 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
178 d_if(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
179 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
180 char *expr;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
181 bool val;
16
9dda765ee85c expression evaluator
David A. Holland
parents: 15
diff changeset
182 struct place p3 = *p2;
82
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
183 size_t oldlen;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
184
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
185 expr = macroexpand(p2, line, strlen(line), true);
82
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
186
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
187 oldlen = strlen(expr);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
188 uncomment(expr);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
189 /* trim to fit, so the malloc debugging won't complain */
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
190 expr = dorealloc(expr, oldlen + 1, strlen(expr) + 1);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
191
127
a0a86380456e fix for #if handling:
David A. Holland
parents: 109
diff changeset
192 if (ifstate->curtrue) {
a0a86380456e fix for #if handling:
David A. Holland
parents: 109
diff changeset
193 val = eval(&p3, expr);
a0a86380456e fix for #if handling:
David A. Holland
parents: 109
diff changeset
194 } else {
a0a86380456e fix for #if handling:
David A. Holland
parents: 109
diff changeset
195 val = 0;
a0a86380456e fix for #if handling:
David A. Holland
parents: 109
diff changeset
196 }
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
197 ifstate_push(&lp->current, val);
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
198 dostrfree(expr);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
199 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
200
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
201 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
202 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
203 d_ifdef(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
204 {
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
205 uncomment(line);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
206 oneword("#ifdef", p2, line);
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
207 ifstate_push(&lp->current, macro_isdefined(line));
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
208 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
209
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
210 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
211 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
212 d_ifndef(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
213 {
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
214 uncomment(line);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
215 oneword("#ifndef", p2, line);
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
216 ifstate_push(&lp->current, !macro_isdefined(line));
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
217 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
218
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
219 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
220 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
221 d_elif(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
222 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
223 char *expr;
16
9dda765ee85c expression evaluator
David A. Holland
parents: 15
diff changeset
224 struct place p3 = *p2;
82
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
225 size_t oldlen;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
226
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
227 if (ifstate->seenelse) {
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
228 complain(&lp->current, "#elif after #else");
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
229 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
230 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
231
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
232 if (ifstate->evertrue) {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
233 ifstate->curtrue = false;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
234 } else {
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
235 expr = macroexpand(p2, line, strlen(line), true);
82
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
236
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
237 oldlen = strlen(expr);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
238 uncomment(expr);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
239 /* trim to fit, so the malloc debugging won't complain */
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
240 expr = dorealloc(expr, oldlen + 1, strlen(expr) + 1);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
241
16
9dda765ee85c expression evaluator
David A. Holland
parents: 15
diff changeset
242 ifstate->curtrue = eval(&p3, expr);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
243 ifstate->evertrue = ifstate->curtrue;
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
244 dostrfree(expr);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
245 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
246 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
247
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
248 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
249 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
250 d_else(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
251 {
103
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
252 (void)p2;
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
253 (void)line;
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
254
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
255 if (ifstate->seenelse) {
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
256 complain(&lp->current,
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
257 "Multiple #else directives in one conditional");
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
258 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
259 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
260
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
261 ifstate->curtrue = !ifstate->evertrue;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
262 ifstate->evertrue = true;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
263 ifstate->seenelse = true;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
264 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
265
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
266 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
267 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
268 d_endif(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
269 {
103
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
270 (void)p2;
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
271 (void)line;
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
272
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
273 if (ifstate->prev == NULL) {
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
274 complain(&lp->current, "Unmatched #endif");
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
275 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
276 } else {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
277 ifstate_pop();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
278 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
279 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
280
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
281 ////////////////////////////////////////////////////////////
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
282 // macros
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
283
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
284 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
285 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
286 d_define(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
287 {
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
288 size_t pos, argpos;
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
289 struct place p3, p4;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
290
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
291 (void)lp;
103
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
292
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
293 /*
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
294 * line may be:
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
295 * macro expansion
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
296 * macro(arg, arg, ...) expansion
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
297 */
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
298
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
299 pos = strcspn(line, " \t\f\v(");
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
300 if (line[pos] == '(') {
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
301 line[pos++] = '\0';
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
302 argpos = pos;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
303 pos = pos + strcspn(line+pos, "()");
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
304 if (line[pos] == '(') {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
305 p2->column += pos;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
306 complain(p2, "Left parenthesis in macro parameters");
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
307 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
308 return;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
309 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
310 if (line[pos] != ')') {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
311 p2->column += pos;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
312 complain(p2, "Unclosed macro parameter list");
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
313 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
314 return;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
315 }
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
316 line[pos++] = '\0';
36
a489cc223483 Don't demand space after the macro argument parenthesis.
David A. Holland
parents: 30
diff changeset
317 #if 0
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
318 if (!strchr(ws, line[pos])) {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
319 p2->column += pos;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
320 complain(p2, "Trash after macro parameter list");
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
321 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
322 return;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
323 }
36
a489cc223483 Don't demand space after the macro argument parenthesis.
David A. Holland
parents: 30
diff changeset
324 #endif
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
325 } else if (line[pos] == '\0') {
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
326 argpos = 0;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
327 } else {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
328 line[pos++] = '\0';
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
329 argpos = 0;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
330 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
331
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
332 pos += strspn(line+pos, ws);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
333
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
334 p3 = *p2;
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
335 p3.column += argpos;
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
336
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
337 p4 = *p2;
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
338 p4.column += pos;
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
339
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
340 if (argpos) {
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
341 macro_define_params(p2, line, &p3,
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
342 line + argpos, &p4,
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
343 line + pos);
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
344 } else {
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
345 macro_define_plain(p2, line, &p4, line + pos);
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 16
diff changeset
346 }
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
347 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
348
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
349 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
350 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
351 d_undef(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
352 {
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
353 (void)lp;
103
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
354
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
355 uncomment(line);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
356 oneword("#undef", p2, line);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
357 macro_undef(line);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
358 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
359
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
360 ////////////////////////////////////////////////////////////
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
361 // includes
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
362
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
363 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
364 bool
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
365 tryinclude(struct place *p, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
366 {
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
367 size_t len;
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
368
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
369 len = strlen(line);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
370 if (len > 2 && line[0] == '"' && line[len-1] == '"') {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
371 line[len-1] = '\0';
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
372 file_readquote(p, line+1);
62
90c6052410ce Don't truncate the candidate include path strings.
David A. Holland
parents: 49
diff changeset
373 line[len-1] = '"';
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
374 return true;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
375 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
376 if (len > 2 && line[0] == '<' && line[len-1] == '>') {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
377 line[len-1] = '\0';
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
378 file_readbracket(p, line+1);
62
90c6052410ce Don't truncate the candidate include path strings.
David A. Holland
parents: 49
diff changeset
379 line[len-1] = '>';
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
380 return true;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
381 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
382 return false;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
383 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
384
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
385 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
386 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
387 d_include(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
388 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
389 char *text;
82
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
390 size_t oldlen;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
391
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
392 uncomment(line);
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
393 if (tryinclude(&lp->current, line)) {
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
394 return;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
395 }
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
396 text = macroexpand(p2, line, strlen(line), false);
82
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
397
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
398 oldlen = strlen(text);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
399 uncomment(text);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
400 /* trim to fit, so the malloc debugging won't complain */
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
401 text = dorealloc(text, oldlen + 1, strlen(text) + 1);
05a94332f08b In #if/#elif, prune comments *after* macro expansion.
David A. Holland
parents: 81
diff changeset
402
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
403 if (tryinclude(&lp->current, text)) {
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
404 dostrfree(text);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
405 return;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
406 }
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
407 complain(&lp->current, "Illegal #include directive");
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
408 complain(&lp->current, "Before macro expansion: #include %s", line);
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
409 complain(&lp->current, "After macro expansion: #include %s", text);
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
410 dostrfree(text);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
411 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
412 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
413
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
414 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
415 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
416 d_line(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
417 {
103
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
418 (void)p2;
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
419 (void)line;
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
420
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
421 /* XXX */
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
422 complain(&lp->current, "Sorry, no #line yet");
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
423 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
424
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
425 ////////////////////////////////////////////////////////////
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
426 // messages
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
427
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
428 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
429 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
430 d_warning(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
431 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
432 char *msg;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
433
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
434 msg = macroexpand(p2, line, strlen(line), false);
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
435 complain(&lp->current, "#warning: %s", msg);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
436 if (mode.werror) {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
437 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
438 }
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
439 dostrfree(msg);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
440 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
441
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
442 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
443 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
444 d_error(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
445 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
446 char *msg;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
447
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
448 msg = macroexpand(p2, line, strlen(line), false);
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
449 complain(&lp->current, "#error: %s", msg);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
450 complain_fail();
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
451 dostrfree(msg);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
452 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
453
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
454 ////////////////////////////////////////////////////////////
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
455 // other
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
456
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
457 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
458 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
459 d_pragma(struct lineplace *lp, struct place *p2, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
460 {
103
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
461 (void)p2;
343af355df1b Pass -Wunused.
David A. Holland
parents: 99
diff changeset
462
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
463 complain(&lp->current, "#pragma %s", line);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
464 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
465 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
466
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
467 ////////////////////////////////////////////////////////////
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
468 // directive table
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
469
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
470 static const struct {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
471 const char *name;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
472 bool ifskip;
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
473 void (*func)(struct lineplace *, struct place *, char *line);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
474 } directives[] = {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
475 { "define", true, d_define },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
476 { "elif", false, d_elif },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
477 { "else", false, d_else },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
478 { "endif", false, d_endif },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
479 { "error", true, d_error },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
480 { "if", false, d_if },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
481 { "ifdef", false, d_ifdef },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
482 { "ifndef", false, d_ifndef },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
483 { "include", true, d_include },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
484 { "line", true, d_line },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
485 { "pragma", true, d_pragma },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
486 { "undef", true, d_undef },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
487 { "warning", true, d_warning },
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
488 };
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
489 static const unsigned numdirectives = HOWMANY(directives);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
490
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
491 static
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
492 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
493 directive_gotdirective(struct lineplace *lp, char *line)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
494 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
495 struct place p2;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
496 size_t len, skip;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
497 unsigned i;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
498
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
499 p2 = lp->current;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
500 for (i=0; i<numdirectives; i++) {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
501 len = strlen(directives[i].name);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
502 if (!strncmp(line, directives[i].name, len) &&
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
503 strchr(ws, line[len])) {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
504 if (directives[i].ifskip && !ifstate->curtrue) {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
505 return;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
506 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
507 skip = len + strspn(line+len, ws);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
508 p2.column += skip;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
509 line += skip;
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
510
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
511 len = strlen(line);
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
512 len = notrailingws(line, len);
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
513 if (len < strlen(line)) {
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
514 line[len] = '\0';
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
515 }
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
516 directives[i].func(lp, &p2, line);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
517 return;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
518 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
519 }
83
3e505c16b0b0 Accept # by itself, including with a comment after it.
David A. Holland
parents: 82
diff changeset
520 /* ugh. allow # by itself, including with a comment after it */
3e505c16b0b0 Accept # by itself, including with a comment after it.
David A. Holland
parents: 82
diff changeset
521 uncomment(line);
3e505c16b0b0 Accept # by itself, including with a comment after it.
David A. Holland
parents: 82
diff changeset
522 if (line[0] == '\0') {
3e505c16b0b0 Accept # by itself, including with a comment after it.
David A. Holland
parents: 82
diff changeset
523 return;
3e505c16b0b0 Accept # by itself, including with a comment after it.
David A. Holland
parents: 82
diff changeset
524 }
3e505c16b0b0 Accept # by itself, including with a comment after it.
David A. Holland
parents: 82
diff changeset
525
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
526 skip = strcspn(line, ws);
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
527 complain(&lp->current, "Unknown directive #%.*s", (int)skip, line);
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
528 complain_fail();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
529 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
530
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
531 /*
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
532 * Check for nested comment delimiters in LINE.
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
533 */
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
534 static
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
535 size_t
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
536 directive_scancomments(const struct lineplace *lp, char *line, size_t len)
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
537 {
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
538 size_t pos;
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
539 bool incomment;
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
540 struct place p2;
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
541
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
542 p2 = lp->current;
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
543 incomment = 0;
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
544 for (pos = 0; pos+1 < len; pos++) {
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
545 if (line[pos] == '/' && line[pos+1] == '*') {
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
546 if (incomment) {
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
547 complain(&p2, "Warning: %c%c within comment",
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
548 '/', '*');
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
549 if (mode.werror) {
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
550 complain_failed();
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
551 }
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
552 } else {
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
553 incomment = true;
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
554 }
109
4483a14ee101 Make -Wcomment work again
David A. Holland
parents: 103
diff changeset
555 pos++;
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
556 } else if (line[pos] == '*' && line[pos+1] == '/') {
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
557 if (incomment) {
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
558 incomment = false;
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
559 } else {
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
560 /* stray end-comment; should we care? */
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
561 }
109
4483a14ee101 Make -Wcomment work again
David A. Holland
parents: 103
diff changeset
562 pos++;
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
563 }
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
564 if (line[pos] == '\n') {
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
565 p2.line++;
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
566 p2.column = 0;
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
567 } else {
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
568 p2.column++;
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
569 }
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
570 }
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
571
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
572 /* multiline comments are supposed to arrive in a single buffer */
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
573 assert(!incomment);
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
574 return len;
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
575 }
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
576
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
577 void
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
578 directive_gotline(struct lineplace *lp, char *line, size_t len)
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
579 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
580 size_t skip;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
581
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
582 if (warns.nestcomment) {
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
583 directive_scancomments(lp, line, len);
49
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
584 }
8a204d153398 Intercept multiline comments earlier. Leave same-line comments alone.
David A. Holland
parents: 39
diff changeset
585
66
f8507e5ed84c Recognize directive lines only when the # is exactly in column 0.
David A. Holland
parents: 64
diff changeset
586 /* check if we have a directive line (# exactly in column 0) */
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
587 if (line[0] == '#') {
66
f8507e5ed84c Recognize directive lines only when the # is exactly in column 0.
David A. Holland
parents: 64
diff changeset
588 skip = 1 + strspn(line + 1, ws);
77
123168887da8 Clean out old not-really-working nested comment handling.
David A. Holland
parents: 72
diff changeset
589 assert(skip <= len);
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
590 lp->current.column += skip;
64
f50b4ea6cbfe Prune single-line comments from (most) directive lines.
David A. Holland
parents: 62
diff changeset
591 assert(line[len] == '\0');
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
592 directive_gotdirective(lp, line+skip /*, length = len-skip */);
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
593 lp->current.column += len-skip;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
594 } else if (ifstate->curtrue) {
154
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
595 macro_sendline(&lp->current, line, len);
a2c2fe8dbea3 Wrap up the current and next line position when invoking directives.
David A. Holland
parents: 128
diff changeset
596 lp->current.column += len;
15
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
597 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
598 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
599
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
600 void
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
601 directive_goteof(struct place *p)
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
602 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
603 while (ifstate->prev != NULL) {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
604 complain(p, "Missing #endif");
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
605 complain(&ifstate->startplace, "...opened at this point");
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
606 complain_failed();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
607 ifstate_pop();
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
608 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
609 macro_sendeof(p);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
610 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
611
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
612 ////////////////////////////////////////////////////////////
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
613 // module initialization
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
614
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
615 void
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
616 directive_init(void)
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
617 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
618 ifstate = ifstate_create(NULL, NULL, true);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
619 }
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
620
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
621 void
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
622 directive_cleanup(void)
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
623 {
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
624 assert(ifstate->prev == NULL);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
625 ifstate_destroy(ifstate);
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
626 ifstate = NULL;
f6177d3ed5c2 handle directives
David A. Holland
parents:
diff changeset
627 }