diff --git a/parser.c b/parser.c index 4ef4b53..d76059c 100644 --- a/parser.c +++ b/parser.c @@ -323,6 +323,41 @@ void qmi_message_parse(enum message_type message_type) list_add(&qmi_messages, &qm->node); } +struct list_head qmi_structs = LIST_INIT(qmi_structs); + +void qmi_struct_parse(void) +{ + struct qmi_struct_member *qsm; + struct token struct_id_tok; + struct qmi_struct *qs; + struct token type_tok; + struct token id_tok; + + token_expect(TOK_ID, &struct_id_tok); + token_expect('{', NULL); + + qs = malloc(sizeof(struct qmi_struct)); + qs->name = struct_id_tok.str; + list_init(&qs->members); + + while (token_accept(TOK_TYPE, &type_tok)) { + token_expect(TOK_ID, &id_tok); + token_expect(';', NULL); + + qsm = malloc(sizeof(struct qmi_struct_member)); + qsm->name = id_tok.str; + qsm->type = type_tok.num; + + list_add(&qs->members, &qsm->node); + } + + token_expect('}', NULL); + token_expect(';', NULL); + + list_add(&qmi_structs, &qs->node); + + symbol_add(qs->name, TOK_TYPE, TYPE_STRUCT, qs); +} const char *qmi_package; diff --git a/qmi_struct.c b/qmi_struct.c index a21ab58..de3b58f 100644 --- a/qmi_struct.c +++ b/qmi_struct.c @@ -4,57 +4,6 @@ #include "list.h" #include "qmic.h" -struct qmi_struct_member { - const char *name; - int type; - - struct list_head node; -}; - -struct qmi_struct { - const char *name; - - struct list_head node; - - struct list_head members; -}; - -static struct list_head qmi_structs = LIST_INIT(qmi_structs); - -void qmi_struct_parse(void) -{ - struct qmi_struct_member *qsm; - struct token struct_id_tok; - struct qmi_struct *qs; - struct token type_tok; - struct token id_tok; - - token_expect(TOK_ID, &struct_id_tok); - token_expect('{', NULL); - - qs = malloc(sizeof(struct qmi_struct)); - qs->name = struct_id_tok.str; - list_init(&qs->members); - - while (token_accept(TOK_TYPE, &type_tok)) { - token_expect(TOK_ID, &id_tok); - token_expect(';', NULL); - - qsm = malloc(sizeof(struct qmi_struct_member)); - qsm->name = id_tok.str; - qsm->type = type_tok.num; - - list_add(&qs->members, &qsm->node); - } - - token_expect('}', NULL); - token_expect(';', NULL); - - list_add(&qmi_structs, &qs->node); - - symbol_add(qs->name, TOK_TYPE, TYPE_STRUCT, qs); -} - void qmi_struct_header(FILE *fp, const char *package) { struct qmi_struct_member *qsm; diff --git a/qmic.h b/qmic.h index 8ca8ed1..8f020d6 100644 --- a/qmic.h +++ b/qmic.h @@ -69,9 +69,24 @@ struct qmi_message { struct list_head members; }; +struct qmi_struct_member { + const char *name; + int type; + + struct list_head node; +}; + +struct qmi_struct { + const char *name; + + struct list_head node; + + struct list_head members; +}; + extern struct list_head qmi_consts; extern struct list_head qmi_messages; - +extern struct list_head qmi_structs; void yyerror(const char *fmt, ...) __attribute__((noreturn));