parser: Move struct parser to parser.c

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson
2018-01-30 16:13:06 -08:00
parent 63f0bedbda
commit 7e7d2a2a17
3 changed files with 51 additions and 52 deletions

View File

@@ -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;

View File

@@ -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;

17
qmic.h
View File

@@ -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));