From: Matthias Kruk Date: Sun, 12 Jul 2020 06:18:24 +0000 (+0900) Subject: parser: Implement parsing of type names and abstract declarators X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=70e3ad4fa71ec84557c578f43c09bbdc1d4c5b32;p=ccc parser: Implement parsing of type names and abstract declarators --- 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);