Mercurial > ~dholland > hg > tradcpp > index.cgi
changeset 164:f14f5352956c
Merge upstream into Joerg's changes.
author | David A. Holland |
---|---|
date | Fri, 12 Jun 2015 01:00:38 -0400 |
parents | e1dfa3f90b6c (current diff) a2c2fe8dbea3 (diff) |
children | cc6d6f27d6ee |
files | directive.c directive.h files.c macro.c place.h |
diffstat | 5 files changed, 78 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/directive.c Fri Feb 27 13:44:39 2015 +0100 +++ b/directive.c Fri Jun 12 01:00:38 2015 -0400 @@ -175,7 +175,7 @@ static void -d_if(struct place *p, struct place *p2, struct place *np, char *line) +d_if(struct lineplace *lp, struct place *p2, char *line) { char *expr; bool val; @@ -194,38 +194,38 @@ } else { val = 0; } - ifstate_push(p, val); + ifstate_push(&lp->current, val); dostrfree(expr); } static void -d_ifdef(struct place *p, struct place *p2, struct place *np, char *line) +d_ifdef(struct lineplace *lp, struct place *p2, char *line) { uncomment(line); oneword("#ifdef", p2, line); - ifstate_push(p, macro_isdefined(line)); + ifstate_push(&lp->current, macro_isdefined(line)); } static void -d_ifndef(struct place *p, struct place *p2, struct place *np, char *line) +d_ifndef(struct lineplace *lp, struct place *p2, char *line) { uncomment(line); oneword("#ifndef", p2, line); - ifstate_push(p, !macro_isdefined(line)); + ifstate_push(&lp->current, !macro_isdefined(line)); } static void -d_elif(struct place *p, struct place *p2, struct place *np, char *line) +d_elif(struct lineplace *lp, struct place *p2, char *line) { char *expr; struct place p3 = *p2; size_t oldlen; if (ifstate->seenelse) { - complain(p, "#elif after #else"); + complain(&lp->current, "#elif after #else"); complain_fail(); } @@ -247,13 +247,14 @@ static void -d_else(struct place *p, struct place *p2, struct place *np, char *line) +d_else(struct lineplace *lp, struct place *p2, char *line) { (void)p2; (void)line; if (ifstate->seenelse) { - complain(p, "Multiple #else directives in one conditional"); + complain(&lp->current, + "Multiple #else directives in one conditional"); complain_fail(); } @@ -264,13 +265,13 @@ static void -d_endif(struct place *p, struct place *p2, struct place *np, char *line) +d_endif(struct lineplace *lp, struct place *p2, char *line) { (void)p2; (void)line; if (ifstate->prev == NULL) { - complain(p, "Unmatched #endif"); + complain(&lp->current, "Unmatched #endif"); complain_fail(); } else { ifstate_pop(); @@ -282,12 +283,12 @@ static void -d_define(struct place *p, struct place *p2, struct place *np, char *line) +d_define(struct lineplace *lp, struct place *p2, char *line) { size_t pos, argpos; struct place p3, p4; - (void)p; + (void)lp; /* * line may be: @@ -347,9 +348,9 @@ static void -d_undef(struct place *p, struct place *p2, struct place *np, char *line) +d_undef(struct lineplace *lp, struct place *p2, char *line) { - (void)p; + (void)lp; uncomment(line); oneword("#undef", p2, line); @@ -383,13 +384,13 @@ static void -d_include(struct place *p, struct place *p2, struct place *np, char *line) +d_include(struct lineplace *lp, struct place *p2, char *line) { char *text; size_t oldlen; uncomment(line); - if (tryinclude(p, line)) { + if (tryinclude(&lp->current, line)) { return; } text = macroexpand(p2, line, strlen(line), false); @@ -399,20 +400,20 @@ /* trim to fit, so the malloc debugging won't complain */ text = dorealloc(text, oldlen + 1, strlen(text) + 1); - if (tryinclude(p, text)) { + if (tryinclude(&lp->current, text)) { dostrfree(text); return; } - complain(p, "Illegal #include directive"); - complain(p, "Before macro expansion: #include %s", line); - complain(p, "After macro expansion: #include %s", text); + complain(&lp->current, "Illegal #include directive"); + complain(&lp->current, "Before macro expansion: #include %s", line); + complain(&lp->current, "After macro expansion: #include %s", text); dostrfree(text); complain_fail(); } static void -d_line(struct place *p, struct place *p2, struct place *np, char *line) +d_line(struct lineplace *lp, struct place *p2, char *line) { char *text; size_t oldlen; @@ -455,19 +456,19 @@ goto illegal_line; } } - np->line = atoi(start_lineno); + lp->nextline.line = atoi(start_lineno); if (len_filename) { char *filename = dostrndup(start_filename, len_filename); - place_setfile(np, filename); + place_setfile(&lp->nextline, filename); dostrfree(filename); } dostrfree(text); return; illegal_line: - complain(p, "Illegal #line directive"); - complain(p, "Before macro expansion: #include %s", line); - complain(p, "After macro expansion: #include %s", text); + complain(&lp->current, "Illegal #line directive"); + complain(&lp->current, "Before macro expansion: #include %s", line); + complain(&lp->current, "After macro expansion: #include %s", text); dostrfree(text); } @@ -476,12 +477,12 @@ static void -d_warning(struct place *p, struct place *p2, struct place *np, char *line) +d_warning(struct lineplace *lp, struct place *p2, char *line) { char *msg; msg = macroexpand(p2, line, strlen(line), false); - complain(p, "#warning: %s", msg); + complain(&lp->current, "#warning: %s", msg); if (mode.werror) { complain_fail(); } @@ -490,12 +491,12 @@ static void -d_error(struct place *p, struct place *p2, struct place *np, char *line) +d_error(struct lineplace *lp, struct place *p2, char *line) { char *msg; msg = macroexpand(p2, line, strlen(line), false); - complain(p, "#error: %s", msg); + complain(&lp->current, "#error: %s", msg); complain_fail(); dostrfree(msg); } @@ -505,11 +506,11 @@ static void -d_pragma(struct place *p, struct place *p2, struct place *np, char *line) +d_pragma(struct lineplace *lp, struct place *p2, char *line) { (void)p2; - complain(p, "#pragma %s", line); + complain(&lp->current, "#pragma %s", line); complain_fail(); } @@ -519,8 +520,7 @@ static const struct { const char *name; bool ifskip; - void (*func)(struct place *, struct place *, struct place *, - char *line); + void (*func)(struct lineplace *, struct place *, char *line); } directives[] = { { "define", true, d_define }, { "elif", false, d_elif }, @@ -540,13 +540,13 @@ static void -directive_gotdirective(struct place *p, struct place *np, char *line) +directive_gotdirective(struct lineplace *lp, char *line) { struct place p2; size_t len, skip; unsigned i; - p2 = *p; + p2 = lp->current; for (i=0; i<numdirectives; i++) { len = strlen(directives[i].name); if (!strncmp(line, directives[i].name, len) && @@ -563,7 +563,7 @@ if (len < strlen(line)) { line[len] = '\0'; } - directives[i].func(p, &p2, np, line); + directives[i].func(lp, &p2, line); return; } } @@ -574,7 +574,7 @@ } skip = strcspn(line, ws); - complain(p, "Unknown directive #%.*s", (int)skip, line); + complain(&lp->current, "Unknown directive #%.*s", (int)skip, line); complain_fail(); } @@ -583,13 +583,13 @@ */ static size_t -directive_scancomments(const struct place *p, char *line, size_t len) +directive_scancomments(const struct lineplace *lp, char *line, size_t len) { size_t pos; bool incomment; struct place p2; - p2 = *p; + p2 = lp->current; incomment = 0; for (pos = 0; pos+1 < len; pos++) { if (line[pos] == '/' && line[pos+1] == '*') { @@ -625,25 +625,25 @@ } void -directive_gotline(struct place *p, struct place *np, char *line, size_t len) +directive_gotline(struct lineplace *lp, char *line, size_t len) { size_t skip; if (warns.nestcomment) { - directive_scancomments(p, line, len); + directive_scancomments(lp, line, len); } /* check if we have a directive line (# exactly in column 0) */ if (line[0] == '#') { skip = 1 + strspn(line + 1, ws); assert(skip <= len); - p->column += skip; + lp->current.column += skip; assert(line[len] == '\0'); - directive_gotdirective(p, np, line+skip); - p->column += len-skip; + directive_gotdirective(lp, line+skip /*, length = len-skip */); + lp->current.column += len-skip; } else if (ifstate->curtrue) { - macro_sendline(p, line, len); - p->column += len; + macro_sendline(&lp->current, line, len); + lp->current.column += len; } }
--- a/directive.h Fri Feb 27 13:44:39 2015 +0100 +++ b/directive.h Fri Jun 12 01:00:38 2015 -0400 @@ -29,11 +29,21 @@ #include <stddef.h> -struct place; +#include "place.h" + +/* + * Relevant places while we're processing a line: + * the place in the current line + * the beginning of the next line + */ +struct lineplace { + struct place current; + struct place nextline; +}; void directive_init(void); void directive_cleanup(void); -void directive_gotline(struct place *p, struct place *np, char *line, size_t len); +void directive_gotline(struct lineplace *lp, char *line, size_t len); void directive_goteof(struct place *p);
--- a/files.c Fri Feb 27 13:44:39 2015 +0100 +++ b/files.c Fri Jun 12 01:00:38 2015 -0400 @@ -172,14 +172,15 @@ void file_read(const struct placefile *pf, int fd, const char *name, bool toplevel) { - struct place linestartplace, nextlinestartplace, ptmp; + struct lineplace places; + struct place ptmp; size_t bufend, bufmax, linestart, lineend, nextlinestart, tmp; ssize_t result; bool ateof = false; char *buf; - place_setfilestart(&linestartplace, pf); - nextlinestartplace = linestartplace; + place_setfilestart(&places.current, pf); + places.nextline = places.current; bufmax = 128; bufend = 0; @@ -223,7 +224,7 @@ } else if (result == 0) { /* eof in middle of line */ ateof = true; - ptmp = linestartplace; + ptmp = places.current; ptmp.column += bufend - linestart; complain(&ptmp, "No newline at end of file"); if (mode.werror) { @@ -244,7 +245,7 @@ assert(buf[lineend] == '\n'); buf[lineend] = '\0'; nextlinestart = lineend+1; - nextlinestartplace.line++; + places.nextline.line++; /* check for CR/NL */ if (lineend > 0 && buf[lineend-1] == '\r') { @@ -271,21 +272,21 @@ assert(buf[lineend] == '\0'); /* count how many commented-out newlines we swallowed */ - nextlinestartplace.line += countnls(buf, linestart, lineend); + places.nextline.line += countnls(buf, linestart, lineend); /* if the line isn't empty, process it */ if (lineend > linestart) { - directive_gotline(&linestartplace, &nextlinestartplace, + directive_gotline(&places, buf+linestart, lineend-linestart); } linestart = nextlinestart; lineend = findeol(buf, linestart, bufend); - linestartplace = nextlinestartplace; + places.current = places.nextline; } if (toplevel) { - directive_goteof(&linestartplace); + directive_goteof(&places.current); } dofree(buf, bufmax); }
--- a/macro.c Fri Feb 27 13:44:39 2015 +0100 +++ b/macro.c Fri Jun 12 01:00:38 2015 -0400 @@ -930,6 +930,8 @@ expand_send(es, p, buf, len); break; case ES_WANTLPAREN: + /* XXX notyet */ + //expand_send(es, p, buf, len); break; case ES_NOARG: expand_newarg(es, buf, len);
--- a/place.h Fri Feb 27 13:44:39 2015 +0100 +++ b/place.h Fri Jun 12 01:00:38 2015 -0400 @@ -27,6 +27,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef PLACE_H +#define PLACE_H + #include <stdbool.h> enum places { @@ -56,3 +59,5 @@ const struct placefile *place_addfile(const struct place *incplace, const char *name, bool fromsystemdir); + +#endif /* PLACE_H */