Add __alignof__.
This commit is contained in:
parent
80be26da9a
commit
1a90c89fed
@ -1,5 +1,5 @@
|
||||
%{
|
||||
/* $NetBSD: cgram.y,v 1.43 2009/05/01 22:03:36 christos Exp $ */
|
||||
/* $NetBSD: cgram.y,v 1.44 2009/05/02 16:10:49 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.43 2009/05/01 22:03:36 christos Exp $");
|
||||
__RCSID("$NetBSD: cgram.y,v 1.44 2009/05/02 16:10:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -130,6 +130,7 @@ 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_ALIGNOF
|
||||
%token <y_op> T_MULT
|
||||
%token <y_op> T_DIVOP
|
||||
%token <y_op> T_ADDOP
|
||||
@ -195,7 +196,7 @@ static inline void RESTORE(const char *file, size_t line)
|
||||
%left T_SHFTOP
|
||||
%left T_ADDOP
|
||||
%left T_MULT T_DIVOP
|
||||
%right T_UNOP T_INCDEC T_SIZEOF T_REAL T_IMAG
|
||||
%right T_UNOP T_INCDEC T_SIZEOF T_ALIGNOF T_REAL T_IMAG
|
||||
%left T_LPARN T_LBRACK T_STROP
|
||||
|
||||
%token <y_sb> T_NAME
|
||||
@ -1694,6 +1695,9 @@ term:
|
||||
| T_SIZEOF T_LPARN type_name T_RPARN %prec T_SIZEOF {
|
||||
$$ = bldszof($3);
|
||||
}
|
||||
| T_ALIGNOF T_LPARN type_name T_RPARN %prec T_ALIGNOF {
|
||||
$$ = bldalof($3);
|
||||
}
|
||||
| T_LPARN type_name T_RPARN term %prec T_UNOP {
|
||||
$$ = cast($4, $2);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: err.c,v 1.41 2009/05/01 22:03:36 christos Exp $ */
|
||||
/* $NetBSD: err.c,v 1.42 2009/05/02 16:10:49 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.41 2009/05/01 22:03:36 christos Exp $");
|
||||
__RCSID("$NetBSD: err.c,v 1.42 2009/05/02 16:10:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -202,10 +202,10 @@ const char *msgs[] = {
|
||||
"modulus by 0", /* 140 */
|
||||
"integer overflow detected, op %s", /* 141 */
|
||||
"floating point overflow detected, op %s", /* 142 */
|
||||
"cannot take size of incomplete type", /* 143 */
|
||||
"cannot take size of function", /* 144 */
|
||||
"cannot take size of bit-field", /* 145 */
|
||||
"cannot take size of void", /* 146 */
|
||||
"cannot take size/alignment of incomplete type", /* 143 */
|
||||
"cannot take size/alignment of function", /* 144 */
|
||||
"cannot take size/alignment of bit-field", /* 145 */
|
||||
"cannot take size/alignment of void", /* 146 */
|
||||
"invalid cast expression", /* 147 */
|
||||
"improper cast of void expression", /* 148 */
|
||||
"illegal function", /* 149 */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: externs1.h,v 1.26 2009/04/15 01:20:57 christos Exp $ */
|
||||
/* $NetBSD: externs1.h,v 1.27 2009/05/02 16:10:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
@ -200,6 +200,7 @@ extern tnode_t *promote(op_t, int, tnode_t *);
|
||||
extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
|
||||
extern void cvtcon(op_t, int, type_t *, val_t *, val_t *);
|
||||
extern tnode_t *bldszof(type_t *);
|
||||
extern tnode_t *bldalof(type_t *);
|
||||
extern tnode_t *cast(tnode_t *, type_t *);
|
||||
extern tnode_t *funcarg(tnode_t *, tnode_t *);
|
||||
extern tnode_t *funccall(tnode_t *, tnode_t *);
|
||||
|
@ -1,5 +1,5 @@
|
||||
%{
|
||||
/* $NetBSD: scan.l,v 1.43 2009/04/15 01:20:57 christos Exp $ */
|
||||
/* $NetBSD: scan.l,v 1.44 2009/05/02 16:10:49 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.43 2009/04/15 01:20:57 christos Exp $");
|
||||
__RCSID("$NetBSD: scan.l,v 1.44 2009/05/02 16:10:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -193,6 +193,7 @@ static struct kwtab {
|
||||
u_int kw_c99; /* c99 keyword */
|
||||
u_int kw_gcc; /* GCC keyword */
|
||||
} kwtab[] = {
|
||||
{ "__alignof__",T_ALIGNOF, 0, 0, 0, 0, 0, 0 },
|
||||
{ "asm", T_ASM, 0, 0, 0, 0, 0, 1 },
|
||||
{ "__asm", T_ASM, 0, 0, 0, 0, 0, 0 },
|
||||
{ "__asm__", T_ASM, 0, 0, 0, 0, 0, 0 },
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tree.c,v 1.58 2009/04/27 15:08:10 ginsbach Exp $ */
|
||||
/* $NetBSD: tree.c,v 1.59 2009/05/02 16:10:49 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.58 2009/04/27 15:08:10 ginsbach Exp $");
|
||||
__RCSID("$NetBSD: tree.c,v 1.59 2009/05/02 16:10:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -3097,6 +3097,55 @@ bldszof(type_t *tp)
|
||||
return (getinode(st, (int64_t)(elem * elsz / CHAR_BIT)));
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
tnode_t *
|
||||
bldalof(type_t *tp)
|
||||
{
|
||||
tspec_t st;
|
||||
|
||||
switch (tp->t_tspec) {
|
||||
case ARRAY:
|
||||
break;
|
||||
|
||||
case FUNC:
|
||||
/* cannot take align of function */
|
||||
error(144);
|
||||
return 0;
|
||||
|
||||
case STRUCT:
|
||||
case UNION:
|
||||
if (incompl(tp)) {
|
||||
/* cannot take align of incomplete type */
|
||||
error(143);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case ENUM:
|
||||
break;
|
||||
default:
|
||||
if (tp->t_isfield) {
|
||||
/* cannot take align of bit-field */
|
||||
error(145);
|
||||
return 0;
|
||||
}
|
||||
if (tp->t_tspec == VOID) {
|
||||
/* cannot take alignsize of void */
|
||||
error(146);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#if SIZEOF_IS_ULONG
|
||||
st = ULONG;
|
||||
#else
|
||||
st = UINT;
|
||||
#endif
|
||||
|
||||
return getinode(st, (int64_t)getbound(tp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Type casts.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user