From 70e3ad4fa71ec84557c578f43c09bbdc1d4c5b32 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 12 Jul 2020 15:18:24 +0900 Subject: [PATCH] parser: Implement parsing of type names and abstract declarators --- src/parser.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- src/parser.h | 1 + 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/parser.c b/src/parser.c index fecb569..0859d4a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -862,8 +862,53 @@ struct cast_expression *parse_cast_expression(void) struct type_name *parse_type_name(void) { - fprintf(stderr, "FIXME: %s() is not implemented\n", __func__); - return(NULL); + struct type_name *name; + + name = type_name_new(); + + /* + * type-name: + * specifier-qualifier-list abstract-declarator_opt + */ + + if(name) { + name->sqlist = parse_specifier_qualifier_list(); + + if(name->sqlist) { + /* we don't check the return value because the abstract declarator is optional */ + name->absdecl = parse_abstract_declarator(); + } else { + type_name_free(name); + name = NULL; + } + } + + return(name); +} + +struct abstract_declarator *parse_abstract_declarator(void) +{ + struct abstract_declarator *decl; + + decl = abstract_declarator_new(); + + /* + * abstract-declarator: + * pointer + * pointer_opt direct-abstract-declarator + */ + + if(decl) { + decl->pointer = parse_pointer(); + decl->dadecl = parse_direct_abstract_declarator(); + + if(!decl->pointer && !decl->dadecl) { + abstract_declarator_free(decl); + decl = NULL; + } + } + + return(decl); } struct logical_or_expression *parse_logical_or_expression(void) diff --git a/src/parser.h b/src/parser.h index 1951d02..fc09c09 100644 --- a/src/parser.h +++ b/src/parser.h @@ -11,6 +11,7 @@ struct constant *parse_constant(void); struct string *parse_string(void); struct type_name *parse_type_name(void); +struct abstract_declarator *parse_abstract_declarator(void); struct assignment_expression *parse_assignment_expression(void); struct logical_or_expression *parse_logical_or_expression(void); struct logical_and_expression *parse_logical_and_expression(void); -- 2.47.3