commit fcb4b5f352c01905cca5075de822e4f28a6b7e33
parent 8343145ebf02b4a351b9a7fda1a402fbd7c512ca
Author: Bor Grošelj Simić <bgs@turminal.net>
Date: Thu, 2 Jun 2022 00:33:44 +0200
store enum value location
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
Diffstat:
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/ast.h b/include/ast.h
@@ -31,6 +31,7 @@ struct ast_list_type {
};
struct ast_enum_field {
+ struct location loc;
const char *name;
struct ast_expression *value;
struct ast_enum_field *next;
diff --git a/src/check.c b/src/check.c
@@ -3712,7 +3712,7 @@ resolve_type(struct context *ctx, const struct scope_object *obj)
if (idecl->type != IDECL_DECL || idecl->decl.decl_type != AST_DECL_TYPE) {
struct location loc;
if (idecl->type == IDECL_ENUM_FLD) {
- loc = idecl->field->type->loc;
+ loc = idecl->field->field->loc;
} else {
loc = idecl->decl.loc;
}
@@ -3868,7 +3868,7 @@ wrap_resolver(struct context *ctx, const struct scope_object *obj,
if (idecl->in_progress) {
struct location loc;
if (idecl->type == IDECL_ENUM_FLD) {
- loc = idecl->field->type->loc;
+ loc = idecl->field->field->loc;
} else {
loc = idecl->decl.loc;
}
diff --git a/src/parse.c b/src/parse.c
@@ -433,6 +433,7 @@ parse_enum_type(struct identifier *ident, struct lexer *lexer)
*next = xcalloc(1, sizeof(struct ast_enum_field));
want(lexer, T_NAME, &tok);
(*next)->name = tok.name;
+ (*next)->loc = tok.loc;
if (lex(lexer, &tok) == T_EQUAL) {
(*next)->value = parse_expression(lexer);
} else {