diff options
| author | rajdakin <rajdakin@gmail.com> | 2024-09-07 20:53:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-07 20:53:51 +0200 |
| commit | f30d75ae5dba339bfc95229894b22fd73e3fdc14 (patch) | |
| tree | 5cd75da181f43a7aaf29cab121069d9dba85aa2d /wrapperhelper/src/prepare.c | |
| parent | e087e7782ca9b2ce6c8ec99706a352b1c6ca12bc (diff) | |
| download | box64-f30d75ae5dba339bfc95229894b22fd73e3fdc14.tar.gz box64-f30d75ae5dba339bfc95229894b22fd73e3fdc14.zip | |
[WRAPPERHELPER] General improvements (#1804)
* [WRAPPERHELPER] Automatic headers detection, various bug fixes, added some cast support * [WRAPPERHELPER] Keep comments untouched
Diffstat (limited to 'wrapperhelper/src/prepare.c')
| -rw-r--r-- | wrapperhelper/src/prepare.c | 82 |
1 files changed, 62 insertions, 20 deletions
diff --git a/wrapperhelper/src/prepare.c b/wrapperhelper/src/prepare.c index 994d8292..616f2332 100644 --- a/wrapperhelper/src/prepare.c +++ b/wrapperhelper/src/prepare.c @@ -14,6 +14,7 @@ struct prepare_s { PREPST_INCL, PREPST_DEF, PREPST_DEFID, + PREPST_COMMENT, } st; }; @@ -154,6 +155,37 @@ static const struct symbs_s { }; preproc_token_t pre_next_token(prepare_t *src, int allow_comments) { + if (src->st == PREPST_COMMENT) { + // In comments, keep everything as 'BLANK' except for idents, newlines and EOF + int c = get_char(src); + if (c == EOF) { + // Force newline at EOF + unget_char(src, c); + src->st = PREPST_NL; + return (preproc_token_t){ + .tokt = PPTOK_NEWLINE, + .tokv.c = (char)c + }; + } else if ((c == '_') || ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))) { + preproc_token_t ret; + ret.tokt = PPTOK_IDENT; + ret.tokv.str = string_new_cap(1); + string_add_char(ret.tokv.str, (char)c); + fill_ident(src, ret.tokv.str); + return ret; + } else if ((c >= 0) && (c <= 0x7F)) { + return (preproc_token_t){ + .tokt = PPTOK_BLANK, + .tokv.c = (char)c + }; + } else { + return (preproc_token_t){ + .tokt = PPTOK_INVALID, + .tokv.c = (char)c + }; + } + } + start_next_token: int c = get_char(src); if (c == EOF) { @@ -259,7 +291,7 @@ start_next_token: c = get_char(src); if (c == '/') { if (allow_comments) { - src->st = PREPST_NONE; + src->st = PREPST_COMMENT; return (preproc_token_t){ .tokt = PPTOK_START_LINE_COMMENT, .tokv.c = '/' @@ -288,6 +320,14 @@ start_next_token: .tokv.c = (char)c }; } else if (c == '*') { + if (allow_comments) { + printf("Unsupported multiline comment with allow_comment in %s\n", src->srcn); + return (preproc_token_t){ + .tokt = PPTOK_INVALID, + .tokv.c = (char)c + }; + } + c = get_char(src); int last_star = 0; while ((c != EOF) && (!last_star || (c != '/'))) { @@ -349,24 +389,26 @@ start_next_token: .tokv.c = (char)c }; } -preproc_token_t pre_next_newline_token(prepare_t *src) { -start_next_token: - int c = get_char(src); - if (c == EOF) { - // Force newline at EOF - unget_char(src, c); - src->st = PREPST_NL; - return (preproc_token_t){ - .tokt = PPTOK_NEWLINE, - .tokv.c = (char)c - }; - } - if (c == '\n') { - src->st = PREPST_NL; - return (preproc_token_t){ - .tokt = PPTOK_NEWLINE, - .tokv.c = (char)c - }; + +// Warning: unsafe method +void prepare_mark_nocomment(prepare_t *src) { + src->st = PREPST_NONE; +} +int pre_next_newline_token(prepare_t *src, string_t *buf) { + while (1) { + int c = get_char(src); + if (c == EOF) { + // Force newline at EOF + unget_char(src, c); + src->st = PREPST_NL; + return 1; + } else if (c == '\n') { + src->st = PREPST_NL; + return 1; + } else if ((c >= 0) && (c <= 0x7F)) { + if (!string_add_char(buf, (char)c)) return 0; + } else { + return 0; + } } - goto start_next_token; } |