aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--expr.c11
-rw-r--r--type.c12
-rw-r--r--type.h2
3 files changed, 14 insertions, 11 deletions
diff --git a/expr.c b/expr.c
index d30669c..e8a1ff0 100644
--- a/expr.c
+++ b/expr.c
@@ -481,9 +481,10 @@ postfixexpr(struct scope *s, struct expr *r)
{
struct expr *e, *arr, *idx, *tmp, **end;
struct type *t;
- enum typequal tq;
struct param *p;
+ struct member *m;
uint64_t offset;
+ enum typequal tq;
enum tokenkind op;
bool lvalue;
@@ -569,11 +570,13 @@ postfixexpr(struct scope *s, struct expr *r)
lvalue = op == TARROW || r->unary.base->flags & EXPRFLAG_LVAL;
r = exprconvert(r, mkpointertype(&typechar));
offset = 0;
- t = typemember(t, tok.lit, &offset);
- if (!t)
+ m = typemember(t, tok.lit, &offset);
+ if (!m)
error(&tok.loc, "struct/union has no member named '%s'", tok.lit);
+ if (m->bits.before || m->bits.after)
+ error(&tok.loc, "bit-field access is not yet supported");
r = mkbinaryexpr(&tok.loc, TADD, r, mkconstexpr(&typeulong, offset));
- r = exprconvert(r, mkpointertype(mkqualifiedtype(t, tq)));
+ r = exprconvert(r, mkpointertype(mkqualifiedtype(m->type, tq)));
e = mkunaryexpr(TMUL, r);
if (!lvalue)
e->flags &= ~EXPRFLAG_LVAL;
diff --git a/type.c b/type.c
index 8189ca1..43c74cd 100644
--- a/type.c
+++ b/type.c
@@ -296,23 +296,23 @@ typecommonreal(struct type *t1, struct type *t2)
fatal("internal error; could not find common real type");
}
-struct type *
+struct member *
typemember(struct type *t, const char *name, uint64_t *offset)
{
- struct member *m;
+ struct member *m, *sub;
assert(t->kind == TYPESTRUCT || t->kind == TYPEUNION);
for (m = t->structunion.members; m; m = m->next) {
if (m->name) {
if (strcmp(m->name, name) == 0) {
*offset += m->offset;
- return m->type;
+ return m;
}
} else {
- t = typemember(m->type, name, offset);
- if (t) {
+ sub = typemember(m->type, name, offset);
+ if (sub) {
*offset += m->offset;
- return t;
+ return sub;
}
}
}
diff --git a/type.h b/type.h
index c6e0f46..6311f45 100644
--- a/type.h
+++ b/type.h
@@ -110,7 +110,7 @@ struct type *typecommonreal(struct type *, struct type *);
struct type *typeargpromote(struct type *);
struct type *typeintpromote(struct type *);
enum typeprop typeprop(struct type *);
-struct type *typemember(struct type *, const char *, uint64_t *);
+struct member *typemember(struct type *, const char *, uint64_t *);
struct param *mkparam(char *, struct type *);