summaryrefslogtreecommitdiff
path: root/parse/type.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-08-11 22:45:11 -0700
committerOri Bernstein <ori@eigenstate.org>2016-08-11 22:45:11 -0700
commit1db8622646327359d06877fb85534a33cfa5ad6b (patch)
treefbac54e9d3a49effde5d85191d36536259bd3f31 /parse/type.c
parentf78dafbaa956467530295bba1caeaa61e783f274 (diff)
downloadmc-1db8622646327359d06877fb85534a33cfa5ad6b.tar.gz
Error if we duplicate struct members.
Diffstat (limited to 'parse/type.c')
-rw-r--r--parse/type.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/parse/type.c b/parse/type.c
index 7b1adc5..581b2b4 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -291,10 +291,23 @@ Type *mktyfunc(Srcloc loc, Node **args, size_t nargs, Type *ret)
Type *mktystruct(Srcloc loc, Node **decls, size_t ndecls)
{
Type *t;
+ Htab *ht;
+ int i;
+ char *s;
t = mktype(loc, Tystruct);
t->nsub = 0;
t->nmemb = ndecls;
+
+ ht = mkht(strhash, streq);
+ for (i = 0; i < ndecls; i++) {
+ s = declname(decls[i]);
+ if (hthas(ht, s))
+ fatal(decls[i], "duplicate struct member %s\n", declname(decls[i]));
+ htput(ht, s, s);
+ }
+ htfree(ht);
+
t->sdecls = memdup(decls, ndecls * sizeof(Node *));
return t;
}