add __extension__ and typeof

This commit is contained in:
christos 2014-02-18 22:01:36 +00:00
parent e7cf1ceb60
commit 34fd6c876e
4 changed files with 23 additions and 10 deletions

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: cgram.y,v 1.57 2014/02/04 08:08:59 njoly Exp $ */
/* $NetBSD: cgram.y,v 1.58 2014/02/18 22:01:36 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: cgram.y,v 1.57 2014/02/04 08:08:59 njoly Exp $");
__RCSID("$NetBSD: cgram.y,v 1.58 2014/02/18 22:01:36 christos Exp $");
#endif
#include <stdlib.h>
@ -130,6 +130,8 @@ static inline void RESTORE(const char *file, size_t line)
%token <y_op> T_UNOP
%token <y_op> T_INCDEC
%token T_SIZEOF
%token T_TYPEOF
%token T_EXTENSION
%token T_ALIGNOF
%token <y_op> T_MULT
%token <y_op> T_DIVOP
@ -553,6 +555,9 @@ notype_typespec:
T_TYPE {
$$ = gettyp($1);
}
| T_TYPEOF T_LPARN term T_RPARN {
$$ = $3->tn_type;
}
| struct_spec {
popdecl();
$$ = $1;
@ -1732,6 +1737,9 @@ term:
| T_IMAG T_LPARN term T_RPARN {
$$ = build(IMAG, $3, NULL);
}
| T_EXTENSION T_LPARN term T_RPARN {
$$ = $3;
}
| T_SIZEOF term %prec T_SIZEOF {
if (($$ = $2 == NULL ? NULL : bldszof($2->tn_type)) != NULL)
chkmisc($2, 0, 0, 0, 0, 0, 1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.46 2013/04/19 17:43:05 christos Exp $ */
/* $NetBSD: err.c,v 1.47 2014/02/18 22:01:36 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: err.c,v 1.46 2013/04/19 17:43:05 christos Exp $");
__RCSID("$NetBSD: err.c,v 1.47 2014/02/18 22:01:36 christos Exp $");
#endif
#include <sys/types.h>
@ -208,7 +208,7 @@ const char *msgs[] = {
"cannot take size/alignment of void", /* 146 */
"invalid cast expression", /* 147 */
"improper cast of void expression", /* 148 */
"illegal function", /* 149 */
"illegal function (type %s)", /* 149 */
"argument mismatch: %d arg%s passed, %d expected", /* 150 */
"void expressions may not be arguments, arg #%d", /* 151 */
"argument cannot have unknown size, arg #%d", /* 152 */

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: scan.l,v 1.53 2013/10/18 20:46:09 christos Exp $ */
/* $NetBSD: scan.l,v 1.54 2014/02/18 22:01:36 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: scan.l,v 1.53 2013/10/18 20:46:09 christos Exp $");
__RCSID("$NetBSD: scan.l,v 1.54 2014/02/18 22:01:36 christos Exp $");
#endif
#include <stdlib.h>
@ -230,6 +230,7 @@ static struct kwtab {
{ "double", T_TYPE, 0, DOUBLE, 0, 0, 0, 0 },
{ "else", T_ELSE, 0, 0, 0, 0, 0, 0 },
{ "enum", T_ENUM, 0, 0, 0, 0, 0, 0 },
{ "__extension__", T_EXTENSION, 0, 0, 0, 0, 0, 1 },
{ "extern", T_SCLASS, EXTERN, 0, 0, 0, 0, 0 },
{ "float", T_TYPE, 0, FLOAT, 0, 0, 0, 0 },
{ "for", T_FOR, 0, 0, 0, 0, 0, 0 },
@ -256,6 +257,9 @@ static struct kwtab {
{ "struct", T_SOU, 0, STRUCT, 0, 0, 0, 0 },
{ "switch", T_SWITCH, 0, 0, 0, 0, 0, 0 },
{ "typedef", T_SCLASS, TYPEDEF, 0, 0, 0, 0, 0 },
{ "typeof", T_TYPEOF, 0, 0, 0, 0, 0, 1 },
{ "__typeof", T_TYPEOF, 0, 0, 0, 0, 0, 1 },
{ "__typeof__", T_TYPEOF, 0, 0, 0, 0, 0, 1 },
{ "union", T_SOU, 0, UNION, 0, 0, 0, 0 },
{ "unsigned", T_TYPE, 0, UNSIGN, 0, 0, 0, 0 },
{ "void", T_TYPE, 0, VOID, 0, 0, 0, 0 },

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.74 2014/02/18 20:43:36 christos Exp $ */
/* $NetBSD: tree.c,v 1.75 2014/02/18 22:01:36 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.74 2014/02/18 20:43:36 christos Exp $");
__RCSID("$NetBSD: tree.c,v 1.75 2014/02/18 22:01:36 christos Exp $");
#endif
#include <stdlib.h>
@ -3171,8 +3171,9 @@ funccall(tnode_t *func, tnode_t *args)
if (func->tn_type->t_tspec != PTR ||
func->tn_type->t_subt->t_tspec != FUNC) {
char buf[256];
/* illegal function */
error(149);
error(149, tyname(buf, sizeof(buf), func->tn_type));
return (NULL);
}