aboutsummaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c119
1 files changed, 1 insertions, 118 deletions
diff --git a/src/parse.c b/src/parse.c
index c5ced09..86035cb 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -692,32 +692,6 @@ parse_expr(struct lexer *lexer, struct ast_expr *out)
}
static bool
-parse_import(struct lexer *lexer, struct ast_import *out)
-{
- if (!match(lexer, T_IMPORT)) {
- return false;
- }
-
- if (!parse_path(lexer, &out->path)) {
- error(lex_loc(lexer), "syntax error: expected import path");
- }
-
- struct token token;
- if (lex(lexer, &token) == T_NAME) {
- out->name = token.info.str;
- } else {
- unlex(lexer, &token);
- out->name = out->path.segments[out->path.seglen - 1];
- }
-
- if (!match(lexer, T_SEMICOLON)) {
- error(lex_loc(lexer), "syntax error: expected semicolon");
- }
-
- return true;
-}
-
-static bool
parse_integer(struct lexer *lexer, struct type *out)
{
struct token token;
@@ -852,78 +826,6 @@ parse_struct(struct lexer *lexer, struct type *out)
return true;
}
-static bool
-parse_enum(struct lexer *lexer, struct type *out)
-{
- if (!match(lexer, T_ENUM)) {
- return false;
- }
-
- out->kind = TYP_ENUM;
- // Default tag type is uint
- out->desc.en.tag_type = malloc(sizeof(struct type));
- out->desc.en.tag_type->kind = TYP_INT;
- out->desc.en.tag_type->desc.i.sign = false;
- out->desc.en.tag_type->desc.i.bits = PLATBITS;
-
- if (match(lexer, T_LPAREN)) {
- if (!parse_type(lexer, out->desc.en.tag_type)) {
- error(lex_loc(lexer),
- "syntax error: expected tag type");
- }
-
- if (!match(lexer, T_RPAREN)) {
- error(lex_loc(lexer), "syntax error: expected ')'");
- }
- }
-
- struct disjunction_e init;
- if (match(lexer, T_ASSIGN)) {
- if (!parse_disjunction_e(lexer, &init)) {
- error(lex_loc(lexer),
- "syntax error: expected expression");
- }
- }
-
- if (!match(lexer, T_LBRACE)) {
- error(lex_loc(lexer), "syntax error: expected '{'");
- }
-
- out->desc.en.variants = must_calloc(1, sizeof(struct variant));
- out->desc.en.variantsz = 1;
- out->desc.en.variantlen = 0;
-
- struct token name;
- uint64_t tag = 0;
- bool commabreak = false;
- while (lex(lexer, &name) == T_NAME) {
- if (out->desc.en.variantlen >= out->desc.en.variantsz) {
- out->desc.en.variantsz *= 2;
- size_t sz = sizeof(struct variant) *
- out->desc.en.variantsz;
- out->desc.en.variants = must_realloc(
- out->desc.en.variants, sz);
- }
- out->desc.en.variants[out->desc.en.variantlen].name =
- name.info.str;
- out->desc.en.variants[out->desc.en.variantlen++].tag = tag++;
-
- if (!match(lexer, T_COMMA)) {
- commabreak = true;
- break;
- }
- }
- if (!commabreak) {
- unlex(lexer, &name);
- }
-
- if (!match(lexer, T_RBRACE)) {
- error(lex_loc(lexer), "syntax error: expected '}'");
- }
-
- return true;
-}
-
static bool parse_union(struct lexer *lexer, struct type *out)
{
if (!match(lexer, T_UNION)) {
@@ -1043,9 +945,6 @@ parse_type(struct lexer *lexer, struct type *out)
if (parse_struct(lexer, out)) {
return true;
}
- if (parse_enum(lexer, out)) {
- return true;
- }
if (parse_union(lexer, out)) {
return true;
}
@@ -1186,11 +1085,7 @@ parse_declaration(struct lexer *lexer, struct ast_declaration *out)
return false;
}
- if (match(lexer, T_MUT)) {
- out->mut = true;
- } else {
- out->mut = false;
- }
+ out->mut = false;
struct token name;
if (lex(lexer, &name) != T_NAME) {
@@ -1448,8 +1343,6 @@ parse_function(struct lexer *lexer, struct ast_func *out)
out->paramsz = 1;
out->paramlen = 0;
- out->exported = match(lexer, T_EXPORT);
-
if (!match(lexer, T_FUNC)) {
if (out->exported) {
error(lex_loc(lexer),
@@ -1636,16 +1529,6 @@ parse(struct lexer *lexer, struct ast_unit *ast)
ast->topsz = 1;
ast->toplen = 0;
- struct ast_import import;
- while (parse_import(lexer, &import)) {
- if (ast->implen >= ast->impsz) {
- ast->impsz *= 2;
- size_t sz = sizeof(struct ast_import) * ast->impsz;
- ast->imports = must_realloc(ast->imports, sz);
- }
- ast->imports[ast->implen++] = import;
- }
-
struct ast_toplevel top;
while (parse_toplevel(lexer, &top)) {
if (ast->toplen >= ast->topsz) {