aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkatherine <shmibs@airen-no-jikken.icu>2019-05-23 03:23:59 -0700
committerkatherine <shmibs@airen-no-jikken.icu>2019-05-23 03:23:59 -0700
commit101d5ad1f3e864f3b6442b6063151ffb47178099 (patch)
tree7b2d941bffe231cf7e05eafbd6071016c4d4f507 /src
parent031ff654cf9ad4de5cecf3fabff92e4bb2352c17 (diff)
downloadconfconf-101d5ad1f3e864f3b6442b6063151ffb47178099.tar.gz
add basetype-use-checks to analyse
Diffstat (limited to 'src')
-rw-r--r--src/analyse.c111
-rw-r--r--src/analyse.h12
-rw-r--r--src/gen.c38
-rw-r--r--src/gen.h5
-rw-r--r--src/main.c39
5 files changed, 204 insertions, 1 deletions
diff --git a/src/analyse.c b/src/analyse.c
index 9510f5a..e454f6c 100644
--- a/src/analyse.c
+++ b/src/analyse.c
@@ -6,7 +6,20 @@
struct analyse_result_s analyse(struct parse_result_s pr)
{
- struct analyse_result_s ar;
+ struct analyse_result_s ar = {
+ .uses_bool = false,
+ .uses_string = false,
+ .uses_id = false,
+ .uses_int = false,
+ .uses_intl = false,
+ .uses_intll = false,
+ .uses_uint = false,
+ .uses_uintl = false,
+ .uses_uintll = false,
+ .uses_float = false,
+ .uses_double = false,
+ .uses_doublel = false,
+ };
struct parse_deftype_s *dtp, *tmp_dtp;
struct parse_var_s *vtp, *tmp_vtp;
struct analyse_tree_s *cur;
@@ -70,6 +83,102 @@ struct analyse_result_s analyse(struct parse_result_s pr)
}
}
+ HASH_ITER(hh, pr.vars, vtp, tmp_vtp) {
+ switch (vtp->type
+ - (PARSE_TYPE_ARRAY_BOOL * (vtp->type >= PARSE_TYPE_ARRAY_BOOL))
+ - (PARSE_TYPE_ARRAY_BOOL * (vtp->type >= PARSE_TYPE_HASH_BOOL))
+ ) {
+ case PARSE_TYPE_BOOL:
+ ar.uses_bool = true;
+ break;
+ case PARSE_TYPE_STRING:
+ ar.uses_string = true;
+ break;
+ case PARSE_TYPE_ID:
+ ar.uses_id = true;
+ break;
+ case PARSE_TYPE_INT:
+ ar.uses_int = true;
+ break;
+ case PARSE_TYPE_INTL:
+ ar.uses_intl = true;
+ break;
+ case PARSE_TYPE_INTLL:
+ ar.uses_intll = true;
+ break;
+ case PARSE_TYPE_UINT:
+ ar.uses_uint = true;
+ break;
+ case PARSE_TYPE_UINTL:
+ ar.uses_uintl = true;
+ break;
+ case PARSE_TYPE_UINTLL:
+ ar.uses_uintll = true;
+ break;
+ case PARSE_TYPE_FLOAT:
+ ar.uses_float = true;
+ break;
+ case PARSE_TYPE_DOUBLE:
+ ar.uses_double = true;
+ break;
+ case PARSE_TYPE_DOUBLEL:
+ ar.uses_doublel = true;
+ break;
+ default:
+ HASH_FIND_STR(pr.deftypes, vtp->deftype_name, dtp);
+ assert(dtp != NULL);
+ for (i = 0; i < dtp->member_list_len; i++) {
+ switch (dtp->member_type_list[i]
+ - (PARSE_TYPE_ARRAY_BOOL *
+ (dtp->member_type_list[i] >= PARSE_TYPE_ARRAY_BOOL)
+ )
+ - (PARSE_TYPE_ARRAY_BOOL *
+ (dtp->member_type_list[i] >= PARSE_TYPE_HASH_BOOL)
+ )
+ ) {
+ case PARSE_TYPE_BOOL:
+ ar.uses_bool = true;
+ break;
+ case PARSE_TYPE_STRING:
+ ar.uses_string = true;
+ break;
+ case PARSE_TYPE_ID:
+ ar.uses_id = true;
+ break;
+ case PARSE_TYPE_INT:
+ ar.uses_int = true;
+ break;
+ case PARSE_TYPE_INTL:
+ ar.uses_intl = true;
+ break;
+ case PARSE_TYPE_INTLL:
+ ar.uses_intll = true;
+ break;
+ case PARSE_TYPE_UINT:
+ ar.uses_uint = true;
+ break;
+ case PARSE_TYPE_UINTL:
+ ar.uses_uintl = true;
+ break;
+ case PARSE_TYPE_UINTLL:
+ ar.uses_uintll = true;
+ break;
+ case PARSE_TYPE_FLOAT:
+ ar.uses_float = true;
+ break;
+ case PARSE_TYPE_DOUBLE:
+ ar.uses_double = true;
+ break;
+ case PARSE_TYPE_DOUBLEL:
+ ar.uses_doublel = true;
+ break;
+ default:
+ assert(false);
+ }
+ }
+ }
+ }
+
return ar;
}
diff --git a/src/analyse.h b/src/analyse.h
index 8e21db7..19f1b96 100644
--- a/src/analyse.h
+++ b/src/analyse.h
@@ -18,6 +18,18 @@ struct analyse_tree_s {
};
struct analyse_result_s {
+ bool uses_bool;
+ bool uses_string;
+ bool uses_id;
+ bool uses_int;
+ bool uses_intl;
+ bool uses_intll;
+ bool uses_uint;
+ bool uses_uintl;
+ bool uses_uintll;
+ bool uses_float;
+ bool uses_double;
+ bool uses_doublel;
struct analyse_tree_s deftype_tree;
struct analyse_tree_s var_tree;
};
diff --git a/src/gen.c b/src/gen.c
index e69de29..98e067b 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -0,0 +1,38 @@
+#include "gen.h"
+
+#include "version.h"
+
+#include <time.h>
+
+static const char header[] =
+"#ifndef CONFCONF_PRIV_H\n"
+"#define CONFCONF_PRIV_H\n"
+"\n"
+"#include <stdbool.h>\n"
+"#include <stdio.h>\n"
+"#include <ctype.h>\n"
+"\n"
+"struct confconf_priv_fstate {\n"
+" void *f;\n"
+" int (*gcp)(void *);\n"
+" size_t line;\n"
+" size_t col;\n"
+" size_t byte;\n"
+"};\n"
+"\n"
+"#endif\n"
+;
+
+void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar)
+{
+ time_t t;
+ struct tm *ti;
+
+ time(&t);
+ ti = localtime(&t);
+
+ fprintf(f, "/* generated by %s on %04d-%02d-%02d */\n",
+ VERSION, ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday);
+
+ fprintf(f, header);
+}
diff --git a/src/gen.h b/src/gen.h
index f3cb932..a5b2899 100644
--- a/src/gen.h
+++ b/src/gen.h
@@ -1,4 +1,9 @@
#ifndef CONFCONF_GEN_H
#define CONFCONF_GEN_H
+#include "parse.h"
+#include "analyse.h"
+
+void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar);
+
#endif
diff --git a/src/main.c b/src/main.c
index 0c0e510..77f3c55 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,6 +2,7 @@
#include "opt.h"
#include "parse.h"
#include "analyse.h"
+#include "gen.h"
static void print_tree(struct analyse_tree_s *t)
{
@@ -25,8 +26,10 @@ static void print_tree(struct analyse_tree_s *t)
int main(int argc, char **argv)
{
+ FILE *fo = stdout;
FILE *fi = stdin;
const char *finame = "stdin";
+ const char *foname;
struct parse_result_s pr;
struct analyse_result_s ar;
@@ -38,6 +41,12 @@ int main(int argc, char **argv)
TRY(fi != NULL, "could not read file `%s`", finame);
}
+ if (opt_outfile_str() != NULL) {
+ foname = opt_infile_str();
+ fo = fopen(foname, "w");
+ TRY(fo != NULL, "could not write to file `%s`", foname);
+ }
+
pr = parse(fi, finame);
if (fi != stdin)
@@ -50,6 +59,36 @@ int main(int argc, char **argv)
print_tree(&ar.var_tree);
puts("");
+ if (ar.uses_bool)
+ puts("bool");
+ if (ar.uses_string)
+ puts("string");
+ if (ar.uses_id)
+ puts("id");
+ if (ar.uses_int)
+ puts("int");
+ if (ar.uses_intl)
+ puts("intl");
+ if (ar.uses_intll)
+ puts("intll");
+ if (ar.uses_uint)
+ puts("uint");
+ if (ar.uses_uintl)
+ puts("uintl");
+ if (ar.uses_uintll)
+ puts("uintll");
+ if (ar.uses_float)
+ puts("float");
+ if (ar.uses_double)
+ puts("double");
+ if (ar.uses_doublel)
+ puts("doublel");
+
+ gen(fo, pr, ar);
+
+ if (fo != stdout)
+ fclose(fo);
+
parse_result_wipe(&pr);
analyse_result_wipe(&ar);