small ser fixes: fix warning and allow same message name in different messages object

This commit is contained in:
viandoxdev 2023-05-19 19:29:46 +02:00
parent 8b0dce39dc
commit e5ffd10d4e
No known key found for this signature in database
GPG Key ID: AF1410C5BC10AA25
2 changed files with 5 additions and 4 deletions

View File

@ -403,7 +403,6 @@ static void define_message(Writer *w, const char *prefix, uint16_t tag, Hashmap
wt_format(w, "class %s(%sMessage):\n", name, prefix);
TypeObject *type;
StructObject *obj;
FieldVec fields = vec_clone(&msg.fields);
{
if (msg.attributes & Attr_versioned) {
@ -418,7 +417,6 @@ static void define_message(Writer *w, const char *prefix, uint16_t tag, Hashmap
type->type.struct_.has_funcs = false;
type->type.struct_.fields = *(AnyVec *)&fields;
type->align = ALIGN_8;
obj = (StructObject *)&type->type.struct_;
Layout l = type_layout(type);
hashmap_set(layouts, &l);

View File

@ -1117,6 +1117,7 @@ static void resolve_constants(EvaluationContext *ctx) {
static void resolve_messages(EvaluationContext *ctx) {
AstItemVec *items = ctx->items;
Hashmap *names = hashmap_init(sss_hash, sss_equal, NULL, sizeof(SpannedStringSlice));
Hashmap *message_names = hashmap_init(sss_hash, sss_equal, NULL, sizeof(SpannedStringSlice));
Hashmap *field_names = hashmap_init(sss_hash, sss_equal, NULL, sizeof(SpannedStringSlice));
ctx->messages = (MessagesObjectVec)vec_init();
@ -1166,11 +1167,11 @@ static void resolve_messages(EvaluationContext *ctx) {
SpannedStringSlice name = sss_from_token(msg.ident);
SpannedStringSlice *prev_name = hashmap_get(names, &name);
SpannedStringSlice *prev_name = hashmap_get(message_names, &name);
if (prev_name != NULL) {
vec_push(&ctx->errors, err_duplicate_def(prev_name->span, name.span, ATIdent, name.slice));
} else {
hashmap_set(names, &name);
hashmap_set(message_names, &name);
}
MessageObject message;
@ -1203,11 +1204,13 @@ static void resolve_messages(EvaluationContext *ctx) {
}
}
hashmap_clear(message_names);
vec_push(&ctx->messages, res);
version = ~0;
}
hashmap_drop(names);
hashmap_drop(message_names);
hashmap_drop(field_names);
}