From 63f0bedbda3ebc362b1d04cc6f2ba30ae3c6e859 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Tue, 30 Jan 2018 16:10:54 -0800 Subject: parser: Move message parsing to parser.c Signed-off-by: Bjorn Andersson --- parser.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++- parser.h | 16 ---------- qmi_message.c | 93 ----------------------------------------------------------- qmic.c | 1 - qmic.h | 37 ++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 111 deletions(-) delete mode 100644 parser.h diff --git a/parser.c b/parser.c index ed31fd0..4ef4b53 100644 --- a/parser.c +++ b/parser.c @@ -10,7 +10,6 @@ #include #include "list.h" -#include "parser.h" #include "qmic.h" #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) @@ -252,6 +251,79 @@ static void qmi_const_parse() list_add(&qmi_consts, &qc->node); } +struct list_head qmi_messages = LIST_INIT(qmi_messages); + +void qmi_message_parse(enum message_type message_type) +{ + struct qmi_message_member *qmm; + struct qmi_message *qm; + struct token msg_id_tok; + struct token type_tok; + struct token num_tok; + struct token id_tok; + unsigned array; + bool required; + + token_expect(TOK_ID, &msg_id_tok); + token_expect('{', NULL); + + qm = malloc(sizeof(struct qmi_message)); + qm->name = msg_id_tok.str; + qm->type = message_type; + list_init(&qm->members); + + while (!token_accept('}', NULL)) { + array = 0; + + if (token_accept(TOK_REQUIRED, NULL)) + required = true; + else if (token_accept(TOK_OPTIONAL, NULL)) + required = false; + else + yyerror("expected required, optional or '}'"); + + token_expect(TOK_TYPE, &type_tok); + token_expect(TOK_ID, &id_tok); + + if (token_accept('[', NULL)) { + array = 1; + if (token_accept(TOK_NUM, &num_tok)) { + if (num_tok.num & 0xffff0000) + array = 4; + else if (num_tok.num & 0xff00) + array = 2; + } + + token_expect(']', NULL); + } + + token_expect('=', NULL); + token_expect(TOK_NUM, &num_tok); + token_expect(';', NULL); + + qmm = malloc(sizeof(struct qmi_message_member)); + qmm->name = id_tok.str; + qmm->type = type_tok.num; + qmm->qmi_struct = type_tok.qmi_struct; + qmm->id = num_tok.num; + qmm->required = required; + qmm->array = array; + + list_add(&qm->members, &qmm->node); + } + + if (token_accept('=', NULL)) { + token_expect(TOK_NUM, &num_tok); + + qm->msg_id = num_tok.num; + } + + token_expect(';', NULL); + + list_add(&qmi_messages, &qm->node); +} + + const char *qmi_package; void qmi_parse(void) diff --git a/parser.h b/parser.h deleted file mode 100644 index 5fe7312..0000000 --- a/parser.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __PARSER_H__ -#define __PARSER_H__ - -void qmi_parse(void); - -extern const char *qmi_package; - -struct qmi_const { - const char *name; - unsigned value; - - struct list_head node; -}; -extern struct list_head qmi_consts; - -#endif diff --git a/qmi_message.c b/qmi_message.c index 537fd04..edcb50f 100644 --- a/qmi_message.c +++ b/qmi_message.c @@ -6,99 +6,6 @@ #include "list.h" #include "qmic.h" -struct qmi_message_member { - const char *name; - int type; - struct qmi_struct *qmi_struct; - int id; - bool required; - unsigned array; - - struct list_head node; -}; - -struct qmi_message { - enum message_type type; - const char *name; - unsigned msg_id; - - struct list_head node; - - struct list_head members; -}; - -static struct list_head qmi_messages = LIST_INIT(qmi_messages); - -void qmi_message_parse(enum message_type message_type) -{ - struct qmi_message_member *qmm; - struct qmi_message *qm; - struct token msg_id_tok; - struct token type_tok; - struct token num_tok; - struct token id_tok; - unsigned array; - bool required; - - token_expect(TOK_ID, &msg_id_tok); - token_expect('{', NULL); - - qm = malloc(sizeof(struct qmi_message)); - qm->name = msg_id_tok.str; - qm->type = message_type; - list_init(&qm->members); - - while (!token_accept('}', NULL)) { - array = 0; - - if (token_accept(TOK_REQUIRED, NULL)) - required = true; - else if (token_accept(TOK_OPTIONAL, NULL)) - required = false; - else - yyerror("expected required, optional or '}'"); - - token_expect(TOK_TYPE, &type_tok); - token_expect(TOK_ID, &id_tok); - - if (token_accept('[', NULL)) { - array = 1; - if (token_accept(TOK_NUM, &num_tok)) { - if (num_tok.num & 0xffff0000) - array = 4; - else if (num_tok.num & 0xff00) - array = 2; - } - - token_expect(']', NULL); - } - - token_expect('=', NULL); - token_expect(TOK_NUM, &num_tok); - token_expect(';', NULL); - - qmm = malloc(sizeof(struct qmi_message_member)); - qmm->name = id_tok.str; - qmm->type = type_tok.num; - qmm->qmi_struct = type_tok.qmi_struct; - qmm->id = num_tok.num; - qmm->required = required; - qmm->array = array; - - list_add(&qm->members, &qmm->node); - } - - if (token_accept('=', NULL)) { - token_expect(TOK_NUM, &num_tok); - - qm->msg_id = num_tok.num; - } - - token_expect(';', NULL); - - list_add(&qmi_messages, &qm->node); -} - static void qmi_message_emit_message_type(FILE *fp, const char *package, const char *message) diff --git a/qmic.c b/qmic.c index c7b912e..e2c0bfb 100644 --- a/qmic.c +++ b/qmic.c @@ -10,7 +10,6 @@ #include #include "list.h" -#include "parser.h" #include "qmic.h" const char *sz_simple_types[] = { diff --git a/qmic.h b/qmic.h index 5e117b0..8ca8ed1 100644 --- a/qmic.h +++ b/qmic.h @@ -39,6 +39,40 @@ struct token { extern const char *sz_simple_types[]; +extern const char *qmi_package; + +struct qmi_const { + const char *name; + unsigned value; + + struct list_head node; +}; + +struct qmi_message_member { + const char *name; + int type; + struct qmi_struct *qmi_struct; + int id; + bool required; + unsigned array; + + struct list_head node; +}; + +struct qmi_message { + enum message_type type; + const char *name; + unsigned msg_id; + + struct list_head node; + + struct list_head members; +}; + +extern struct list_head qmi_consts; +extern struct list_head qmi_messages; + + void yyerror(const char *fmt, ...) __attribute__((noreturn)); void symbol_add(const char *name, int token, ...); @@ -55,4 +89,7 @@ void qmi_struct_header(FILE *fp, const char *package); void qmi_struct_emit_prototype(FILE *fp, const char *package, const char *message, const char *member, unsigned array_size, struct qmi_struct *qs); void qmi_struct_emit_accessors(FILE *fp, const char *package, const char *message, const char *member, int member_id, unsigned array_size, struct qmi_struct *qs); +void qmi_parse(void); + + #endif -- cgit v1.2.3