diff options
author | Bjorn Andersson <bjorn.andersson@linaro.org> | 2018-01-30 16:13:06 -0800 |
---|---|---|
committer | Bjorn Andersson <bjorn.andersson@linaro.org> | 2018-01-30 16:13:06 -0800 |
commit | 7e7d2a2a178afa82b402a65241e77442dda89eb2 (patch) | |
tree | 7bb33656dc01d72007dd37f2f1fa901b2977a23d | |
parent | 63f0bedbda3ebc362b1d04cc6f2ba30ae3c6e859 (diff) |
parser: Move struct parser to parser.c
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
-rw-r--r-- | parser.c | 35 | ||||
-rw-r--r-- | qmi_struct.c | 51 | ||||
-rw-r--r-- | qmic.h | 17 |
3 files changed, 51 insertions, 52 deletions
@@ -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; @@ -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)); |