diff options
Diffstat (limited to 'bootstrap')
| -rw-r--r-- | bootstrap/cgen.c | 2 | ||||
| -rw-r--r-- | bootstrap/parse.c | 11 | ||||
| -rw-r--r-- | bootstrap/test.cff | 3 |
3 files changed, 10 insertions, 6 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index 9e13e12..8685ffe 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -232,7 +232,7 @@ genexpr(struct expr *ex) { pri("((%t)%n)", ty, ex); break; case Eget: - pri("%e.%s", ex->get.lhs, ex->get.fld); + pri("%e%s%s", ex->get.lhs, ex->get.lhs->ty->t == TYptr ? "->" : ".", ex->get.fld); break; } } diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 32cd202..9c6f5a8 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -1000,9 +1000,12 @@ pexpostfix(struct parser *P) { }; } else if (lexmatch(P, &tok, '.')) { const char *fnam = (tok = lexexpect(P, TKident)).str; - if (ex.ty->t == TYstruct || ex.ty->t == TYunion) { - int idx = structfldnam2idx(ex.ty, fnam); - struct aggfield *fld = &ex.ty->agg.flds.d[idx]; + const struct type *ty = ex.ty; + if (ty->t == TYptr) + ty = ty->child; + if (ty->t == TYstruct || ty->t == TYunion) { + int idx = structfldnam2idx(ty, fnam); + struct aggfield *fld = &ty->agg.flds.d[idx]; if (idx < 0) fatal(P, tok.span, "%t has no such field `%s'", ex.ty, fnam); @@ -1012,7 +1015,7 @@ pexpostfix(struct parser *P) { ex.ty = fld->ty; ex.get.fld = fnam; } else { - fatal(P, tok.span, "cannot acces `%s': left-hand-side is not an aggregate (%t)", + fatal(P, tok.span, "cannot access `%s': left-hand-side is not an aggregate (%t)", fnam, ex.ty); } } else { diff --git a/bootstrap/test.cff b/bootstrap/test.cff index 46e3b8c..d7f86bf 100644 --- a/bootstrap/test.cff +++ b/bootstrap/test.cff @@ -33,7 +33,8 @@ extern fn main (argc int, argv **u8) int { let colors [3]Color = { :Red, :Green, :Blue } ; let x = Vec2f { .y: 1, .x: 2.4 }; - printf("v = { %g, %g }\n", x.x, x.y); + let p = &x; + printf("v = { %g, %g }\n", x.x, p.y); let is [10]int = { [4] = 1, 2, [1 - 1] = 3 }; isort(is, 10); |