summaryrefslogtreecommitdiffstats
path: root/discover
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-09-12 15:54:36 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-09-24 13:14:59 +0800
commitc0b2be44ee953f9f50737b959e0def6e2df24629 (patch)
tree6115ebdfbff91f426257cf82e20ca73aa5a77561 /discover
parent42e3b424841bb6d8e52802924204f41bd1def070 (diff)
downloadtalos-petitboot-c0b2be44ee953f9f50737b959e0def6e2df24629.tar.gz
talos-petitboot-c0b2be44ee953f9f50737b959e0def6e2df24629.zip
discover/grub2: Use subclass-style structs for AST
Use embedded 'struct grub2_statement' data to create a subclass-style syntax tree of statements. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover')
-rw-r--r--discover/grub2/grub2.h38
-rw-r--r--discover/grub2/parser-api.c42
2 files changed, 41 insertions, 39 deletions
diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h
index cc817ff..0643a72 100644
--- a/discover/grub2/grub2.h
+++ b/discover/grub2/grub2.h
@@ -18,45 +18,43 @@ struct grub2_argv {
struct list words;
};
+struct grub2_statements {
+ struct list list;
+};
+
+struct grub2_statement {
+ struct list_item list;
+ enum {
+ STMT_TYPE_SIMPLE,
+ STMT_TYPE_MENUENTRY,
+ STMT_TYPE_IF,
+ STMT_TYPE_BLOCK,
+ } type;
+};
+
struct grub2_statement_simple {
+ struct grub2_statement st;
struct grub2_argv *argv;
};
struct grub2_statement_menuentry {
+ struct grub2_statement st;
struct grub2_argv *argv;
struct grub2_statements *statements;
};
struct grub2_statement_if {
+ struct grub2_statement st;
struct grub2_statement *condition;
struct grub2_statements *true_case;
struct grub2_statements *false_case;
};
struct grub2_statement_block {
+ struct grub2_statement st;
struct grub2_statements *statements;
};
-struct grub2_statement {
- struct list_item list;
- enum {
- STMT_TYPE_SIMPLE,
- STMT_TYPE_MENUENTRY,
- STMT_TYPE_IF,
- STMT_TYPE_BLOCK,
- } type;
- union {
- struct grub2_statement_simple simple;
- struct grub2_statement_menuentry menuentry;
- struct grub2_statement_if ifstmt;
- struct grub2_statement_block block;
- };
-};
-
-struct grub2_statements {
- struct list list;
-};
-
struct grub2_parser {
void *scanner;
struct grub2_statements *statements;
diff --git a/discover/grub2/parser-api.c b/discover/grub2/parser-api.c
index 37c88a2..d3bec3d 100644
--- a/discover/grub2/parser-api.c
+++ b/discover/grub2/parser-api.c
@@ -14,20 +14,22 @@ struct grub2_statements *create_statements(struct grub2_parser *parser)
struct grub2_statement *create_statement_simple(struct grub2_parser *parser,
struct grub2_argv *argv)
{
- struct grub2_statement *stmt = talloc(parser, struct grub2_statement);
- stmt->type = STMT_TYPE_SIMPLE;
- stmt->simple.argv = argv;
- return stmt;
+ struct grub2_statement_simple *stmt =
+ talloc(parser, struct grub2_statement_simple);
+ stmt->st.type = STMT_TYPE_SIMPLE;
+ stmt->argv = argv;
+ return &stmt->st;
}
struct grub2_statement *create_statement_menuentry(struct grub2_parser *parser,
struct grub2_argv *argv, struct grub2_statements *stmts)
{
- struct grub2_statement *stmt = talloc(parser, struct grub2_statement);
- stmt->type = STMT_TYPE_MENUENTRY;
- stmt->menuentry.argv = argv;
- stmt->menuentry.statements = stmts;
- return stmt;
+ struct grub2_statement_menuentry *stmt =
+ talloc(parser, struct grub2_statement_menuentry);
+ stmt->st.type = STMT_TYPE_MENUENTRY;
+ stmt->argv = argv;
+ stmt->statements = stmts;
+ return &stmt->st;
}
struct grub2_statement *create_statement_if(struct grub2_parser *parser,
@@ -35,21 +37,23 @@ struct grub2_statement *create_statement_if(struct grub2_parser *parser,
struct grub2_statements *true_case,
struct grub2_statements *false_case)
{
- struct grub2_statement *stmt = talloc(parser, struct grub2_statement);
- stmt->type = STMT_TYPE_IF;
- stmt->ifstmt.condition = condition;
- stmt->ifstmt.true_case = true_case;
- stmt->ifstmt.false_case = false_case;
- return stmt;
+ struct grub2_statement_if *stmt =
+ talloc(parser, struct grub2_statement_if);
+ stmt->st.type = STMT_TYPE_IF;
+ stmt->condition = condition;
+ stmt->true_case = true_case;
+ stmt->false_case = false_case;
+ return &stmt->st;
}
struct grub2_statement *create_statement_block(struct grub2_parser *parser,
struct grub2_statements *stmts)
{
- struct grub2_statement *stmt = talloc(parser, struct grub2_statement);
- stmt->type = STMT_TYPE_BLOCK;
- stmt->block.statements = stmts;
- return stmt;
+ struct grub2_statement_block *stmt =
+ talloc(parser, struct grub2_statement_block);
+ stmt->st.type = STMT_TYPE_BLOCK;
+ stmt->statements = stmts;
+ return &stmt->st;
}
void statement_append(struct grub2_statements *stmts,
OpenPOWER on IntegriCloud