summaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-02-24 10:50:16 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-02-24 10:50:16 -0500
commitde339d1c307d16faba52ece22bcc9c24d3789868 (patch)
tree3c87a9f660209355f8cb92c70013c96d7b62590a /types.c
parentb206d88474670956035ff25d5b392fb2925b015d (diff)
accessing struct parameters with .
Diffstat (limited to 'types.c')
-rw-r--r--types.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/types.c b/types.c
index cd61025..5eac674 100644
--- a/types.c
+++ b/types.c
@@ -2337,12 +2337,31 @@ static bool types_expr(Typer *tr, Expression *e) {
e->binary.dot.field = f;
}
}
-
if (!is_field) {
- char *member = ident_to_str(rhs->ident);
- char *struc = type_to_str(struct_type);
- err_print(e->where, "%s is not a member of structure %s.", member, struc);
- return false;
+ Declaration *param = NULL;
+ int ident_idx;
+ arr_foreach(struct_type->struc->params, Declaration, p) {
+ ident_idx = 0;
+ arr_foreach(p->idents, Identifier, ident) {
+ if (ident_eq(*ident, rhs->ident)) {
+ param = p;
+ goto dblbreak_dot;
+ }
+ ++ident_idx;
+ }
+ }
+ dblbreak_dot:
+ if (!param) {
+ char *member = ident_to_str(rhs->ident);
+ char *struc = type_to_str(struct_type);
+ err_print(e->where, "%s is not a member of structure %s.", member, struc);
+ return false;
+ }
+ /* replace with parameter value */
+ e->kind = EXPR_VAL;
+ e->val = *decl_val_at_index(param, ident_idx);
+ *t = *decl_type_at_index(param, ident_idx);
+ break;
}
} else if (struct_type->kind == TYPE_SLICE || struct_type->kind == TYPE_ARR) {
if (!ident_eq_str(rhs->ident, "len")) {