harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4a3ed99fe55e564b696073779454e679170fb377
parent 3b305c020c4e85a92f0818438c9fe516e86f21e8
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Sun,  6 Jun 2021 08:06:57 +0000

Don't accept a tag list for -T

Instead of expecting the tag list to be passed in, use -T to enable
tests. There's no need to support anything more.

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Mconfigure | 1-
Minclude/check.h | 7+++----
Dinclude/tags.h | 21---------------------
Msrc/check.c | 13++++++-------
Msrc/main.c | 15+++++----------
Dsrc/tags.c | 65-----------------------------------------------------------------
6 files changed, 14 insertions(+), 108 deletions(-)

diff --git a/configure b/configure @@ -18,7 +18,6 @@ harec() { src/qinstr.c \ src/qtype.c \ src/scope.c \ - src/tags.c \ src/type_store.c \ src/typedef.c \ src/types.c \ diff --git a/include/check.h b/include/check.h @@ -5,7 +5,6 @@ #include "types.h" #include "type_store.h" -struct build_tags; struct expression; struct scope; @@ -33,7 +32,7 @@ struct context { struct type_store *store; const struct type *fntype; struct identifier *ns; - struct build_tags *tags; + bool is_test; struct scope *unit; struct scope *scope; bool deferring; @@ -100,14 +99,14 @@ struct unit { }; struct scope *check(struct type_store *ts, - struct build_tags *tags, + bool is_test, struct define *defines, const struct ast_unit *aunit, struct unit *unit); struct scope *check_internal(struct type_store *ts, struct modcache **cache, - struct build_tags *tags, + bool is_test, struct define *defines, const struct ast_unit *aunit, struct unit *unit, diff --git a/include/tags.h b/include/tags.h @@ -1,21 +0,0 @@ -#ifndef HARE_TAGS_H -#define HARE_TAGS_H -#include <stdbool.h> - -enum tag_mode { - TAG_INCLUDE, - TAG_EXCLUDE, -}; - -struct build_tags { - const char *tag; - enum tag_mode mode; - struct build_tags *next; -}; - -// Returns NULL on invalid syntax -struct build_tags *parse_tags(char *input); - -bool tag_enabled(struct build_tags *tags, const char *tag); - -#endif diff --git a/src/check.c b/src/check.c @@ -9,7 +9,6 @@ #include "expr.h" #include "mod.h" #include "scope.h" -#include "tags.h" #include "type_store.h" #include "types.h" #include "util.h" @@ -2678,7 +2677,7 @@ check_function(struct context *ctx, const struct ast_decl *adecl) { const struct ast_function_decl *afndecl = &adecl->function; - if ((adecl->function.flags & FN_TEST) && !tag_enabled(ctx->tags, "test")) { + if ((adecl->function.flags & FN_TEST) && !ctx->is_test) { return NULL; } @@ -3217,7 +3216,7 @@ scan_const(struct context *ctx, const struct ast_global_decl *decl) static bool scan_function(struct context *ctx, const struct ast_function_decl *decl) { - if ((decl->flags & FN_TEST) && !tag_enabled(ctx->tags, "test")) { + if ((decl->flags & FN_TEST) && !ctx->is_test) { return true; } const struct ast_type fn_atype = { @@ -3504,7 +3503,7 @@ load_import(struct context *ctx, struct ast_imports *import, struct scope * check_internal(struct type_store *ts, struct modcache **cache, - struct build_tags *tags, + bool is_test, struct define *defines, const struct ast_unit *aunit, struct unit *unit, @@ -3512,7 +3511,7 @@ check_internal(struct type_store *ts, { struct context ctx = {0}; ctx.ns = unit->ns; - ctx.tags = tags; + ctx.is_test = is_test; ctx.store = ts; ctx.store->check_context = &ctx; ctx.modcache = cache; @@ -3676,12 +3675,12 @@ check_internal(struct type_store *ts, struct scope * check(struct type_store *ts, - struct build_tags *tags, + bool is_test, struct define *defines, const struct ast_unit *aunit, struct unit *unit) { struct modcache *modcache[MODCACHE_BUCKETS]; memset(modcache, 0, sizeof(modcache)); - return check_internal(ts, modcache, tags, defines, aunit, unit, false); + return check_internal(ts, modcache, is_test, defines, aunit, unit, false); } diff --git a/src/main.c b/src/main.c @@ -11,7 +11,6 @@ #include "lex.h" #include "parse.h" #include "qbe.h" -#include "tags.h" #include "type_store.h" #include "typedef.h" #include "util.h" @@ -20,7 +19,7 @@ static void usage(const char *argv_0) { fprintf(stderr, - "Usage: %s [-o output] [-T tags...] [-t typdefs] [-N namespace]\n", + "Usage: %s [-o output] [-T] [-t typdefs] [-N namespace]\n", argv_0); } @@ -93,13 +92,13 @@ int main(int argc, char *argv[]) { char *output = NULL, *typedefs = NULL; - struct build_tags *tags = NULL; + bool is_test = false; struct unit unit = {0}; struct lexer lexer; struct define *defines = NULL, *def; int c; - while ((c = getopt(argc, argv, "D:o:T:t:N:")) != -1) { + while ((c = getopt(argc, argv, "D:o:Tt:N:")) != -1) { switch (c) { case 'D': def = parse_define(argv[0], optarg); @@ -110,11 +109,7 @@ main(int argc, char *argv[]) output = optarg; break; case 'T': - tags = parse_tags(optarg); - if (!tags) { - fprintf(stderr, "Invalid tags\n"); - return EXIT_FAILURE; - } + is_test = true; break; case 't': typedefs = optarg; @@ -179,7 +174,7 @@ main(int argc, char *argv[]) static struct type_store ts = {0}; builtin_types_init(); - check(&ts, tags, defines, &aunit, &unit); + check(&ts, is_test, defines, &aunit, &unit); if (stage == STAGE_CHECK) { return EXIT_SUCCESS; } diff --git a/src/tags.c b/src/tags.c @@ -1,65 +0,0 @@ -#include <stdbool.h> -#include <stddef.h> -#include <string.h> -#include "tags.h" -#include "util.h" - -struct build_tags * -parse_tags(char *input) -{ - struct build_tags *tag, **next = &tag; - while (input[0]) { - enum tag_mode mode; - switch (input[0]) { - case '+': - mode = TAG_INCLUDE; - break; - case '-': - mode = TAG_EXCLUDE; - break; - default: - return NULL; - } - ++input; - - char c; - char *tok = NULL; - char *p = strchr(input, '+'), *m = strchr(input, '-'); - if (p && !m) { - tok = p; - } else if (m && !p) { - tok = m; - } else if (m && p) { - tok = m < p ? m : p; - } - - if (tok) { - c = *tok; - *tok = '\0'; - } - - tag = *next = xcalloc(1, sizeof(struct build_tags)); - tag->tag = strdup(input); - tag->mode = mode; - next = &tag->next; - - if (tok) { - *tok = c; - } - - input += strlen(tag->tag); - } - return tag; -} - -bool -tag_enabled(struct build_tags *tags, const char *tag) -{ - while (tags) { - if (strcmp(tags->tag, tag) == 0) { - return tags->mode == TAG_INCLUDE; - } - tags = tags->next; - } - return false; -}