parseproto.y revision f07a2a2ef3832ccd4e9e1584966c139773495d2d
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * CDDL HEADER START
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * The contents of this file are subject to the terms of the
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Common Development and Distribution License, Version 1.0 only
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * (the "License"). You may not use this file except in compliance
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * with the License.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * or http://www.opensolaris.org/os/licensing.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * See the License for the specific language governing permissions
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * and limitations under the License.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * When distributing Covered Code, include this CDDL HEADER in each
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * If applicable, add the following below this CDDL HEADER, with the
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * fields enclosed by brackets "[]" replaced with your own identifying
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * information: Portions Copyright [yyyy] [name of copyright owner]
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * CDDL HEADER END
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Use is subject to license terms.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#pragma ident "%Z%%M% %I% %E% SMI"
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#include "parseproto.h"
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#include <assert.h>
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_spec_t *declspec_Construct(void);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void declspec_Destroy(decl_spec_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_spec_t *declspec_Init(stt_t, char *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *declspec_VerifySTT(stt_t, stt_t);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_spec_t *declspec_AddSTT(decl_spec_t *, stt_t, const char **);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_spec_t *declspec_AddDS(decl_spec_t *,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_spec_t *, const char **);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic stt_t declspec_GetSTT(decl_spec_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *declspec_GetTag(decl_spec_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *type_Construct(void);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void type_Destroy(type_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *type_SetPtr(type_t *, stt_t);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *type_SetFun(type_t *, decl_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *type_AddTail(type_t *, type_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const char *type_Verify(type_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *decl_Construct(void);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *decl_AddArg(decl_t *, decl_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int decl_IsVoid(decl_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int decl_IsVoidArray(decl_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const char *decl_VerifyArgs(decl_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *decl_AddDS(decl_t *, decl_spec_t *, const char **);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *decl_AddTypeTail(decl_t *, type_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *decl_addptr(decl_t *, type_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *decl_addary(decl_t *, char *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *decl_addfun(decl_t *, decl_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *decl_addellipsis(decl_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void type_PrintType(type_t *, int);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void decl_PrintDecl(decl_t *, int);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void decl_PrintTraceInfo(decl_t *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *de_const(char *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int yylex(void);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void yyerror(const char *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int yyparse(void);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(MEM_DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int declspec_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int type_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int decl_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *de_const(char *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%union {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char *s_val;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int i_val;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang stt_t stt_val;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_spec_t *ds_val;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *t_val;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *d_val;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <i_val> ELLIPSIS
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <s_val> INTEGER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <s_val> IDENTIFIER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <s_val> TYPEDEF_NAME
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <s_val> constant_expression
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <stt_val> REGISTER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <stt_val> TYPEDEF EXTERN AUTO STATIC
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <stt_val> VOID CHAR SHORT INT LONG
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <stt_val> FLOAT DOUBLE SIGNED UNSIGNED
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <stt_val> CONST VOLATILE RESTRICT RESTRICT_KYWD
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <stt_val> struct_or_union
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <ds_val> storage_class_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <ds_val> type_qualifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <ds_val> type_qualifier_list
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <ds_val> STRUCT UNION
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%token <ds_val> ENUM
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <ds_val> declaration_specifiers
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <ds_val> type_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <ds_val> struct_or_union_specifier enum_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <ds_val> typedef_name
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <t_val> pointer
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <d_val> declaration
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <d_val> init_declarator_list init_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <d_val> declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <d_val> direct_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <d_val> parameter_type_list parameter_list
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <d_val> parameter_declaration
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <d_val> abstract_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%type <d_val> direct_abstract_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%start declaration
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%%
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * The grammar is derived from ANSI/ISO 9899-1990.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclaration
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : declaration_specifiers init_declarator_list ';'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *dp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang protop = $$ = $2;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* only one declaration allowed */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(protop->d_next == NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (dp = $2; dp && (errstr == NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp = dp->d_next) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *sp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_AddDS(dp, $1, &errstr);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (sp = decl_Verify(dp))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = sp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | error ';'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang protop = $$ = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = "function prototype syntax error";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * XXX - Does not support a "stand-alone" declaration specifier. It is
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * essentially a type declaration, for example:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * typedef enum { FALSE = 0, TRUE = 1 } boolean_t;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * or
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * struct _name { char *first; char *last };
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* XXX | declaration_specifiers */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclaration_specifiers
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : storage_class_specifier declaration_specifiers
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char const *ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_AddDS($2, $1, &ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (errstr == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | storage_class_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | type_specifier declaration_specifiers
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_AddDS($2, $1, &ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (errstr == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | type_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | type_qualifier declaration_specifiers
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_AddDS($2, $1, &ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (errstr == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | type_qualifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstorage_class_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : REGISTER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(SCS_REGISTER, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * XXX - Does not support any storage class specifier other than
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * register, and then only for function arguments.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | TYPEDEF
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(SCS_TYPEDEF, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | EXTERN
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(SCS_EXTERN, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | STATIC
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(SCS_STATIC, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | AUTO
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(SCS_AUTO, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : VOID
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_VOID, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | CHAR
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_CHAR, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | SHORT
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_SHORT, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | INT
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_INT, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | LONG
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_LONG, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | FLOAT
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_FLOAT, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | DOUBLE
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_DOUBLE, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | SIGNED
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_SIGNED, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | UNSIGNED
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_UNSIGNED, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | struct_or_union_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | enum_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | typedef_name
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtypedef_name
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : TYPEDEF_NAME
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_TYPEDEF, $1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * The "restrict" keyword is new in the C99 standard.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * It is type qualifier like const and volatile.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * We are using "_RESTRICT_KYWD" in headers and source code so
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * it is easily turned on and off by various macros at compile time.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * In order for the "restrict" keyword to be recognized you must
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * be using a C99 compliant compiler in its native mode.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_qualifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : CONST
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TQ_CONST, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | VOLATILE
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TQ_VOLATILE, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | RESTRICT
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TQ_RESTRICT, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | RESTRICT_KYWD
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TQ_RESTRICT_KYWD, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstruct_or_union_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : struct_or_union { atIDENT = 1; } IDENTIFIER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init($1, $3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free($3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * XXX - struct or union definitions are not supported. It is generally
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * not done within the context of a function declaration (prototype) or
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * variable definition.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | struct_or_union IDENTIFIER '{' struct_declaration_list '}'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | struct_or_union '{' struct_declaration_list '}'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstruct_or_union
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : STRUCT
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = TS_STRUCT;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | UNION
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = TS_UNION;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fanginit_declarator_list
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : init_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = $1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * XXX - Does not support a comma separated list of declarations or
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * definitions. Function prototypes or variable definitions must be
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * given as one per C statement.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | init_declarator_list ',' init_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_AddArg($1, $3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang*/
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fanginit_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * XXX - Initialization is not supported.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | declarator '=' initializer
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang*/
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangenum_specifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : ENUM { atIDENT = 1; } IDENTIFIER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_Init(TS_ENUM, $3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free($3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * XXX - enumerator definition is not supported for the same reasons
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * struct|union definition is not supported.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | ENUM IDENTIFIER '{' enumerator_list '}'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | ENUM '{' enumerator_list '}'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang*/
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : pointer direct_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addptr($2, $1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdirect_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : IDENTIFIER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_SetName(decl_Construct(), $1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | '(' declarator ')'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = $2;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_declarator '[' constant_expression ']'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addary($1, $3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free($3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_declarator '[' ']'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addary($1, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_declarator '(' parameter_type_list ')'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addfun($1, $3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_declarator '(' ')'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addfun($1, NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangpointer
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : '*' type_qualifier_list
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = type_SetPtr(type_Construct(), ($2)->ds_stt);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($2);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | '*'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = type_SetPtr(type_Construct(), TQ_NONE);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | '*' type_qualifier_list pointer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer type_t *tp = type_Construct();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_SetPtr(tp, ($2)->ds_stt);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($2);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = type_AddTail($3, tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | '*' pointer
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp = type_Construct();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_SetPtr(tp, TQ_NONE);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = type_AddTail($2, tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_qualifier_list
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : type_qualifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | type_qualifier_list type_qualifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* XXX - ignore any error */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = declspec_AddDS($1, $2, &ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($2);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangparameter_type_list
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : parameter_list
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | parameter_list ',' ELLIPSIS
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addellipsis($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangparameter_list
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : parameter_declaration
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *sp = type_Verify($1->d_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (sp)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = sp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = $1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | parameter_list ',' parameter_declaration
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *sp = type_Verify($3->d_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (sp)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = sp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_AddArg($1, $3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangparameter_declaration
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : declaration_specifiers declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_AddDS($2, $1, &ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (errstr == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | declaration_specifiers abstract_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_AddDS($2, $1, &ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (errstr == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | declaration_specifiers
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_AddDS(decl_Construct(), $1, &ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy($1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (errstr == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = ep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangabstract_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : pointer
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addptr(decl_Construct(), $1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | pointer direct_abstract_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addptr($2, $1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_abstract_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdirect_abstract_declarator
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : '(' abstract_declarator ')'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = $2;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_abstract_declarator '[' constant_expression ']'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addary($1, $3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free($3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | '[' constant_expression ']'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addary(decl_Construct(), $2);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free($2);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_abstract_declarator '[' ']'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addary($1, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | '[' ']'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addary(decl_Construct(), NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_abstract_declarator '(' parameter_type_list ')'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addfun($1, $3);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | '(' parameter_type_list ')'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addfun(decl_Construct(), $2);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | direct_abstract_declarator '(' ')'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addfun($1, NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | '(' ')'
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang $$ = decl_addfun(decl_Construct(), NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * XXX - General case constant expressions are not supported. It would
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * be easy to implement (for the most part), but there are no cases to
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * date that require such a facility. The grammar does allow an
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * identifier (or typedef name) to be used since the prototype is not
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * processed by CPP. The only integer constant that is supported is
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decimal.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangconstant_expression
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang : INTEGER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | IDENTIFIER
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang | TYPEDEF_NAME
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang%%
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* Data Declarations */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtypedef struct {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char *name;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int token;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang stt_t stt;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang} keyword_t;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtypedef struct {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang stt_t s_stt;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char *s_str;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang} sttpair_t;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* External Declarations */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const keyword_t *lookup_keyword(const char *);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const char *lookup_sttpair(stt_t);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int getch(void);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void ungetch(int);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void skipwhitespace(void);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int lookahead(int);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void skipcomment(void);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* External Definitions */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *input = NULL; /* current place in the input stream */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* at point in stream were identifier is expected */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int atIDENT = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *protop = NULL; /* pointer to prototype */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const char *errstr = NULL; /* error message */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * lookup_keyword - Given a string, return the keyword_t or NULL.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const keyword_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fanglookup_keyword(const char *name) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang static const keyword_t keytbl[] = {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "register", REGISTER, SCS_REGISTER },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if UNSUPPORTED
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "typedef", TYPEDEF, SCS_TYPEDEF },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "auto", AUTO, SCS_AUTO },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "static", STATIC, SCS_STATIC },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "extern", EXTERN, SCS_EXTERN },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif /* UNSUPPORTED */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "void", VOID, TS_VOID },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "char", CHAR, TS_CHAR },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "short", SHORT, TS_SHORT },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "int", INT, TS_INT },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "long", LONG, TS_LONG },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "float", FLOAT, TS_FLOAT },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "double", DOUBLE, TS_DOUBLE },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "signed", SIGNED, TS_SIGNED },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "unsigned", UNSIGNED, TS_UNSIGNED },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "struct", STRUCT, TS_STRUCT },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "union", UNION, TS_UNION },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "enum", ENUM, TS_ENUM },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "const", CONST, TQ_CONST },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "volatile", VOLATILE, TQ_VOLATILE },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "restrict", RESTRICT, TQ_RESTRICT },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { "_RESTRICT_KYWD",RESTRICT_KYWD, TQ_RESTRICT_KYWD},
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang };
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#define NKEYWORD (sizeof (keytbl)/sizeof (keyword_t))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int i;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (i = 0; i < NKEYWORD; ++i) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char *s = keytbl[i].name;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((*s == *name) && (strcmp(s, name) == 0))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (&keytbl[i]);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * lookup_sttpair - Given an stt_t return a string or NULL.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fanglookup_sttpair(stt_t s) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* valid type specifier combinations */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang static const sttpair_t stttbl[] = {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_VOID, "void" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_CHAR, "char" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED | TS_CHAR, "signed char" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED | TS_CHAR, "unsigned char" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SHORT, "short" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED | TS_SHORT, "signed short" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SHORT | TS_INT, "short int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED | TS_SHORT | TS_INT,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "signed short int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED | TS_SHORT,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "unsigned short" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED | TS_SHORT | TS_INT,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "unsigned short int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_INT, "int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED, "signed" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED | TS_INT, "signed int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_NO_TS, "" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED, "unsigned" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED | TS_INT, "unsigned int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_LONG, "long" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED | TS_LONG, "signed long" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_LONG | TS_INT, "long int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED | TS_LONG | TS_INT,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "signed long int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED | TS_LONG, "unsigned long" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED | TS_LONG | TS_INT,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "unsigned long int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_FLOAT, "float" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_DOUBLE, "double" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_LONG | TS_DOUBLE, "long double" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_STRUCT, "struct" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNION, "union" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_ENUM, "enum" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_TYPEDEF, "" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* non-ANSI type: long long */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_LONGLONG, "long long" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_LONGLONG | TS_INT, "long long int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED | TS_LONGLONG,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "signed long long" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED | TS_LONGLONG,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "unsigned long long" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_SIGNED | TS_LONGLONG | TS_INT,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "signed long long int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang { TS_UNSIGNED | TS_LONGLONG | TS_INT,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "unsigned long long int" },
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang };
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#define NDECLSPEC (sizeof (stttbl)/sizeof (sttpair_t))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int i;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (i = 0; i < NDECLSPEC; ++i)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (s == stttbl[i].s_stt)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (stttbl[i].s_str);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * yylex - return next token from the the input stream.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * The lexical analyzer does not recognize all possible C lexical
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * elements. It only recognizes those associated with function
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declarations (read: prototypes) and data definitions.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangyylex(void) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf[BUFSIZ]; /* string version of token */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int c;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int i = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangrestart:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang skipwhitespace();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (c = getch()) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case '/':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (lookahead('*')) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang skipcomment();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang goto restart;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case '.':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (lookahead('.')) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (lookahead('.'))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (ELLIPSIS);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case EOF:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case '(':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case ')':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case ',':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case '[':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case ']':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case ';':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case '*':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (c);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang default:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((c == '_') || isalpha(c)) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const keyword_t *kp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang do {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang buf[i++] = c;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang c = getch();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } while ((c == '_') || isalnum(c));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ungetch(c);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang buf[i] = '\0';
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((kp = lookup_keyword(buf)) != NULL) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang yylval.stt_val = kp->stt;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (kp->token);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang yylval.s_val = strdup(buf);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ((atIDENT) ? IDENTIFIER : TYPEDEF_NAME);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else if (isdigit(c)) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang do {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang buf[i++] = c;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } while (isdigit(c = getch()));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ungetch(c);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang buf[i] = '\0';
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang yylval.s_val = strdup(buf);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (INTEGER);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (c);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* NOTREACHED */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* getch - return the next character from the input stream. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fanggetch(void) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int c;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((c = *input) == '\0')
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang c = EOF;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang else /* only advance on non-NULL */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang input++;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (c);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* ungetch - return a character to the input stream. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangungetch(int c) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *(--input) = c;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* skipwhitespace - skip over whitespace in the input stream. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangskipwhitespace(void) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int c;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (isspace(c = getch()))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ungetch(c);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* skipcomment - scan ahead to the next end of comment. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangskipcomment(void) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang loop {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int c;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (c = getch()) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case EOF:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case '*':
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (lookahead('/'))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* NOTREACHED */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* lookahead - does next character match 'c'? */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fanglookahead(int c) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int ch = getch();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int match;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (!(match = (ch == c)))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ungetch(ch);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (match);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* putNtabs - write N '\t' to standard output. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker FangputNTabs(int n) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int i;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (i = 0; i < n; ++i)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang putchar('\t');
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif /* DEBUG */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* D E C L A R A T I O N S P E C I F I E R S */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Declaration specifiers encode storage class, type specifier and type
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * qualifier information. This includes any identifiers associated with
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * struct, union or enum declarations. Typedef names are also encoded
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * in declaration specifiers.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* declspec_Construct - allocate and initialize a declspec_t. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_spec_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_Construct(void) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_spec_t *dsp = malloc(sizeof (decl_spec_t));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(dsp != NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dsp->ds_stt = SCS_NONE | TS_NO_TS | TQ_NONE;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dsp->ds_id = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(MEM_DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ++declspec_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dsp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* declspec_Destroy - free a declspec_t. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_Destroy(decl_spec_t *dsp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free(dsp->ds_id);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free(dsp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(MEM_DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang --declspec_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declspec_Init - allocate and initialize a declspec_t given an
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * stt_t and identifier.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) identifier can be NULL.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 2) errors resulting in the stt_t and identifier are ignored.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_spec_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_Init(stt_t s, char *tagp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *p;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_spec_t *dsp = declspec_Construct();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_spec_t tmp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tmp.ds_stt = s;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tmp.ds_id = tagp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_AddDS(dsp, &tmp, &p); /* XXX ignore any error */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dsp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declspec_VerifySTT - verify that the two given stt_t can be combined.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The return value is a const char *, non-NULL to indicate an error.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_VerifySTT(stt_t s1, stt_t s2) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang stt_t result;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((s1 | s2) != (s1 ^ s2))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ("attempt to add declaration specifier "
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "that is already present");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang result = (s1 | s2) & TS_MASK;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (lookup_sttpair(result) == NULL) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (STT_isbasic(result) && STT_isderived(result))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ("attempt to combine basic and "
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "derived types");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (STT_isvoid(result) &&
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (STT_isbasic(result) || STT_isderived(result)))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ("attempt to combine void with "
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "other type specifiers");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (STT_isfloat(result) && STT_isint(result))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ("attempt to combine floating and "
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "integer type specifiers");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (STT_ischar(result) && STT_isint(result))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ("attempt to combine character and "
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "integer type specifiers");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (STT_has_explicit_sign(result) &&
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (STT_isfloat(result) || STT_isderived(result)))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ("attempt to combine signed or "
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "unsigned with float or derived type");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ("invalid declaration specifier");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declspec_AddSTT - add an stt_t to a decl_spec_t.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The "long long" type is handled here.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * If both stt_t include TS_LONG then this is an attempt to use
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * "long long". The TS_LONG is cleared from the s1 and s2 and
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * then TS_LONGLONG is added to s2. The resulting s1 and s2 are
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * passed to declspec_VerifySTT to determine if the result is valid.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 2) This method of handling "long long" does detect the case of
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * "long double long" and all it's variant forms.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_spec_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_AddSTT(decl_spec_t *dsp, stt_t s2, const char **err) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang stt_t s1 = dsp->ds_stt;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* non-ANSI type: long long */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((s1 & TS_LONG) && (s2 & TS_LONG)) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang s1 &= ~(TS_LONG);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dsp->ds_stt = s1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang s2 &= ~(TS_LONG);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang s2 |= TS_LONGLONG;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((*err = declspec_VerifySTT(s1, s2)) == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dsp->ds_stt |= s2;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dsp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declpec_AddDS - add a decl_spec_t to an existing decl_spec_t.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_spec_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_AddDS(decl_spec_t *dsp, decl_spec_t *tsp, const char **err) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_AddSTT(dsp, tsp->ds_stt, err);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((*err == NULL) && tsp->ds_id) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free(dsp->ds_id);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dsp->ds_id = strdup(tsp->ds_id);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(dsp->ds_id != NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dsp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declspec_GetSTT - return the stt_t within a decl_spec_t.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic stt_t
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_GetSTT(decl_spec_t *dsp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dsp->ds_stt);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declspec_GetTag - return the identifier within a decl_spec_t.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_GetTag(decl_spec_t *dsp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dsp->ds_id);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declspec_ToString - convert a decl_spec_t into a string.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The form of the resulting string is always the same, i.e.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * [register] [type_specifier] [const] [volatile]
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * dsp must be correct
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangchar *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdeclspec_ToString(char *bufp, decl_spec_t *dsp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *s;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int something = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *bufp = '\0';
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* storage class specifier */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (dsp->ds_stt & SCS_MASK) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case SCS_REGISTER:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, "register");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang something = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang s = lookup_sttpair(dsp->ds_stt & TS_MASK);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* type specifier */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (dsp->ds_stt & TS_MASK) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case TS_STRUCT:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case TS_UNION:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case TS_ENUM:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (something)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, " ");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, s);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, " ");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, dsp->ds_id);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case TS_TYPEDEF:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (something)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, " ");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, dsp->ds_id);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang default:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (something)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, " ");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, s);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (s)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang something = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (something && (dsp->ds_stt & TQ_MASK))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, " ");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dsp->ds_stt & TQ_CONST) /* type qualifier */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, "const");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dsp->ds_stt & TQ_VOLATILE) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dsp->ds_stt & TQ_CONST)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, " ");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, "volatile");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * It currently acknowledges and ignores restrict or _RESTRICT_KYWD
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * in code generation because of the uncertain behavior of "restrict".
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dsp->ds_stt & TQ_RESTRICT)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dsp->ds_stt & TQ_RESTRICT_KYWD)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(bufp, "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (bufp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* T Y P E M O D I F I E R S */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Type modifiers encode the "array of...", "pointer to ..." and
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * "function returning ..." aspects of C types. The modifiers are kept
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * as a linked list in precedence order. The grammar encodes the
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * precedence order described by the standard.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Type modifiers are always added at the end of list and the list is
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * always traversed from head to tail.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* type_Construct - allocate and initialize a type_t. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_Construct(void) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp = malloc(sizeof (type_t));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp != NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_next = NULL; /* generic */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_dt = DD_NONE;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_nargs = 0; /* DD_FUN */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_ellipsis = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_args = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* DD_PTR */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_stt = (SCS_NONE | TS_NO_TS | TQ_NONE);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_sizestr = NULL; /* DD_ARY */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(MEM_DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ++type_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* type_Destroy - free a type_t list. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_Destroy(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *nextp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (tp->t_dt) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_FUN:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_Destroy(tp->t_args);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_PTR:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_ARY:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free(tp->t_sizestr);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free(tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = nextp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(MEM_DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang --type_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * type_SetPtr - make a type_t into a "pointer to ..." variant.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The stt_t will encode any type qualifiers (const, volatile).
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_SetPtr(type_t *tp, stt_t s) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_dt == DD_NONE);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_dt = DD_PTR;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_stt = s & TQ_MASK;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * type_SetAry - make a type_t into an "array of ...", variant.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The array dimension can be NULL to indicate undefined, i.e. [].
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_SetAry(type_t *tp, char *dim) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_dt == DD_NONE);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_sizestr == NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_dt = DD_ARY;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dim) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_sizestr = strdup(dim);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_sizestr != NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_sizestr = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * type_SetFun - make a type_t into a "function returning ..." variant.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The argument list can be NULL to indicate undefined, i.e. ().
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_SetFun(type_t *tp, decl_t *arglist) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_dt == DD_NONE);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_dt = DD_FUN;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (arglist) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_nargs = decl_GetArgLength(arglist);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_args = arglist;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_ellipsis = arglist->d_ellipsis;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * type_AddTail - add a type_t to the end of an existing type_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The type_t *tp is added to the end of the type_t *dp list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic type_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_AddTail(type_t *dp, type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *lastp = dp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *p;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (p = lastp->t_next)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang lastp = p;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang lastp->t_next = tp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* type_PrintType - print a type_t list onto standard output. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_PrintType(type_t *tp, int lvl) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_spec_t tmp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang putNTabs(lvl);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (tp->t_dt) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_PTR:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tmp.ds_stt = tp->t_stt;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tmp.ds_id = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("[%s] ptr to\n", declspec_ToString(buf, &tmp));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_FUN:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("fun [%d%c] %s\n",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp->t_nargs,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (tp->t_ellipsis)? '+' : '=',
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (tp->t_args)? "with arguments" :
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "undefined arguments");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->t_args) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_PrintDecl(tp->t_args, lvl + 1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->t_ellipsis) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang putNTabs(lvl + 1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("...\n");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_ARY:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("ary [%s] of\n",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (tp->t_sizestr)? tp->t_sizestr : "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif /* DEBUG */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * type_Verify - verify a type_t list for semantic correctness.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) C supports most combinations of type modifiers.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * It does not support three combinations, they are:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * function returning array
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * array of functions
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * function returning function
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 2) The enum values associated with type modifiers (i.e. DD_*)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * cannot be modified without changing the table included within the
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * function.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 3) The function returns NULL to indicate that the type modifier
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * list is valid and non-NULL to indicate an error.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 4) A type_t of NULL is permitted to indicate an empty type_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_Verify(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang static const char *dttbl[4][4] = {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* NONE ARY FUN PTR */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* NONE */ {NULL, NULL, NULL, NULL},
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* ARY */ {NULL, NULL, "array of functions", NULL},
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* FUN */ {NULL, "function returning array",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "function returning function", NULL},
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* PTR */ {NULL, NULL, NULL, NULL},
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang };
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *nextp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang do {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *p;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_type_t nt;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang nt = (nextp = tp->t_next)? nextp->t_dt : DD_NONE;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((p = dttbl[tp->t_dt][nt]) != NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (p);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } while (tp = nextp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* type_GetNext - return the next type_t in the list. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_GetNext(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp->t_next);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * The following group of functions return and or
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * test various aspects of type modifiers.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The three functions: type_IsPtrTo, type_IsFunction and
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * type_IsArray will accept an argument of NULL.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 2) All other functions require one of the above three to be true.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Various asserts are in place to verify correct usage.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_IsArray(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp && (tp->t_dt == DD_ARY));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangchar *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_GetArraySize(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_dt == DD_ARY);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp->t_sizestr);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_IsPtrTo(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp && (tp->t_dt == DD_PTR));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstt_t
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_GetPtrToTypeQual(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_dt == DD_PTR);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp->t_stt);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_IsFunction(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp && (tp->t_dt == DD_FUN));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_GetArgLength(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_dt == DD_FUN);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp->t_nargs);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_IsVarargs(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp && tp->t_dt == DD_PTR)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_dt == DD_FUN);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp->t_ellipsis);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_GetArg(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(tp->t_dt == DD_FUN);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp->t_args);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * type_IsPtrFun - determine if the type_t results in a call-able function.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The argument can be NULL.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 2) The test is true if the type_t list is number of DD_PTR followed
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * by a DD_FUN.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_IsPtrFun(type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (! (tp && (tp->t_dt == DD_PTR)))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (0);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp && (tp->t_dt == DD_PTR))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (tp && (tp->t_dt == DD_FUN));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* D E C L A R A T O R */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * A decl_t encodes the name,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * declaration specifiers and type modifiers of an object.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* decl_Construct - allocate a decl_t. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_Construct(void) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *dp = malloc(sizeof (decl_t));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(dp != NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp->d_name = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp->d_type = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp->d_next = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp->d_ds = declspec_Construct();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp->d_ellipsis = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(MEM_DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ++decl_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* decl_Destroy - free a decl_t list. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangvoid
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_Destroy(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *nextp = dp->d_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_Destroy(dp->d_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_Destroy(dp->d_ds);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free(dp->d_name);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free(dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp = nextp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(MEM_DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang --decl_Construct_calls;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_GetArgLength - return the length of a decl_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) The argument may be NULL to indicate an empty list, len == 0.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_GetArgLength(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int len;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (len = 0; dp; dp = dp->d_next)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ++len;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (len);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * The following group of functions get or test various aspects of a decl_t.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_GetNext(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp->d_next);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstt_t
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_GetDeclSpec(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (declspec_GetSTT(dp->d_ds));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangchar *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_GetDSName(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (declspec_GetTag(dp->d_ds));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangtype_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_GetType(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp->d_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_IsVarargs(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp->d_ellipsis);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_IsFunction(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (type_IsFunction(dp->d_type));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangchar *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_GetName(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp->d_name);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_AddArg - add a decl_t to the end of an decl_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_AddArg(decl_t *dp, decl_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *lastp = dp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *p;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (p = lastp->d_next)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang lastp = p;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang lastp->d_next = tp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_IsVoid - return true if the decl_t is a "pure" void declaration.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_IsVoid(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return ((declspec_GetSTT(dp->d_ds) & TS_VOID) && (dp->d_type == NULL));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_IsVoidArray - return true if the decl_t includes "void []".
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_IsVoidArray(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int retval = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp = dp->d_type;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *np;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (np = type_GetNext(tp))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = np;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang retval = type_IsArray(tp) &&
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (declspec_GetSTT(dp->d_ds) & TS_VOID);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (retval);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_Verify - verify a decl_t.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_Verify(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *ep = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (decl_IsVoid(dp))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ep = "type is void";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang else if (decl_IsVoidArray(dp))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ep = "type is void []";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang else
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ep = type_Verify(dp->d_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_VerifyArgs - verify a decl_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic const char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_VerifyArgs(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *tp = dp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *ep = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int nv = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int nargs = decl_GetArgLength(dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (; dp; dp = dp->d_next)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (decl_IsVoid(dp)) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ++nv;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (decl_GetName(dp))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ep = "argument list includes "
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang "void with identifier";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else if (decl_IsVoidArray(dp))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ep = "argument list includes void []";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (nv) { /* there was some void */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (nargs > 1)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ep = "argument list includes void";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->d_ellipsis)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ep = "argument list includes void and \"...\"";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (ep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* decl_AddDS - add a decl_spec_t to a decl_t. */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_AddDS(decl_t *dp, decl_spec_t *dsp, const char **err) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_AddDS(dp->d_ds, dsp, err);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_SetName - set the name associated with a decl_t.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) Any previously known name is free'd.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_SetName(decl_t *dp, char *s) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang free(dp->d_name);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp->d_name = strdup(s);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang assert(dp->d_name != NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_AddTypeTail - add a type_t to the end of a decl_t type_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_AddTypeTail(decl_t *dp, type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dp->d_type)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_AddTail(dp->d_type, tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang else
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp->d_type = tp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_addptr - add a DD_PTR type_t to the end of a decl_t type_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_addptr(decl_t *dp, type_t *tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_AddTypeTail(dp, tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_addary - allocate and add a DD_ARY type_t to the end of
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * a decl_t type_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_addary(decl_t *dp, char *sizep) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp = type_Construct();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_SetAry(tp, sizep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_AddTypeTail(dp, tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_addfun - allocate and add a DD_FUN type_t to the end of a
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_t type_t list.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_addfun(decl_t *dp, decl_t *arglist) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *sp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp = type_Construct();
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (sp = decl_VerifyArgs(arglist))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang yyerror(sp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_SetFun(tp, arglist);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_AddTypeTail(dp, tp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * decl_addellipsis - set the ellipsis state in a decl_t.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * Note:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * 1) This function is only used in the grammar in the
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * parameter list parsing.
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic decl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_addellipsis(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp->d_ellipsis = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_PrintDecl(decl_t *dp, int lvl) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang putNTabs(lvl);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("name = %s, ds = %s\n",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (dp->d_name)? dp->d_name : "<null>",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_ToString(buf, dp->d_ds));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dp->d_type)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_PrintType(dp->d_type, lvl + 1);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang dp = dp->d_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif /* DEBUG */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangchar_getend(char *s) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (*s != '\0')
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ++s;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (s);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangchar *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_ToString(char *bufp, decl_dts_t out, decl_t *dp,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *altname) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char tmp[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char tmp2[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *namep;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char *bend = bufp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp = dp->d_type;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int ffun = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (out) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang default:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang out = DTS_DECL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /* FALLTHRU */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DTS_DECL:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (altname == NULL) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang namep = dp->d_name;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang namep = altname;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DTS_CAST:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang namep = "(*)";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DTS_RET:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (altname == NULL) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang namep = "_return";
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang namep = altname;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *bufp = '\0';
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcpy(tmp, (namep) ? namep : "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (tp->t_dt) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_PTR:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->t_next &&
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ((tp->t_next->t_dt == DD_ARY) ||
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (tp->t_next->t_dt == DD_FUN))) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (out == DTS_RET) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "(*%s)", namep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "(*%s)", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else if (tp->t_stt == TQ_CONST) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "*const %s", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else if (tp->t_stt == TQ_VOLATILE) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "*volatile %s", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang /*
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * It currently acknowledges and ignores restrict
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * or _RESTRICT_KYWD in code generation because
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang * of the uncertain behavior of "restrict".
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else if (tp->t_stt == TQ_RESTRICT) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "*%s", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else if (tp->t_stt == TQ_RESTRICT_KYWD) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "*%s", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "*%s", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_ARY:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "%s[%s]",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tmp, (tp->t_sizestr)? tp->t_sizestr : "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_FUN:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (out == DTS_RET && ffun == 1) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcpy(bufp, namep);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ffun = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else if (tp->t_args == NULL) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "%s()", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf2[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *argp = tp->t_args;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "%s(", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = char_getend(bufp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (argp = tp->t_args; argp; /* noinc */) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_ToString(buf2, DTS_DECL, argp,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bend, " %s", buf2);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = char_getend(bend);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (argp = argp->d_next) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bend, ",");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = char_getend(bend);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->t_ellipsis) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bend, ", ...");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = char_getend(bend);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bend, ")");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcpy(tmp, bufp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (out == DTS_CAST) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "(%s %s)",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_ToString(tmp2, dp->d_ds), tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "%s %s",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_ToString(tmp2, dp->d_ds), tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (bufp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_t *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_AddArgNames(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int argno = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *p = dp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (decl_IsFunction(dp)) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int argno = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *p = dp->d_type->t_args;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (p) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char *s = decl_GetName(p);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if ((s == NULL) && !decl_IsVoid(p)) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(buf, "arg%d", argno);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang s = strdup(buf);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_SetName(p, s);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang p = p->d_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang ++argno;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangconst char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_Parse(char *str, decl_t **dpp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = NULL; /* setup the (static) globals */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang input = str;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang atIDENT = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang protop = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang yyparse(); /* parse the prototype */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (errstr == NULL) { /* success */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *dpp = protop;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_AddArgNames(protop);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else { /* failure */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *dpp = NULL;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_Destroy(protop);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (errstr);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic void
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangyyerror(const char *err) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang errstr = err;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang/* main */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic int yydebug = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangint
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangmain(int argc, char *argv[]) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int i;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang yydebug = 1;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (i = 1; i < argc; ++i) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang const char *es;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *pp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (es = decl_Parse(argv[i], &pp))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("parse failure: %s\n", es);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if GR_DEBUG
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_PrintDecl(pp, 0);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_AddArgNames(pp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("---\n%s;\n",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_ToString(buf, DTS_DECL, pp, NULL));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("%s\n",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_ToString(buf, DTS_CAST, pp, NULL));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("%s;\n",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_ToString(buf, DTS_RET, pp, "%s"));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#ifdef TRACE
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("\n\nTrace Info\n");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_PrintTraceInfo(pp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_Destroy(pp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#if defined(MEM_DEBUG)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("declspec : %d\n", declspec_Construct_calls);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("type : %d\n", type_Construct_calls);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang printf("decl : %d\n", decl_Construct_calls);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (0);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#ifdef TRACE
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangvoid
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_PrintTraceInfo(decl_t *dp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char f_type[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char f_print[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char a_name[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char a_type[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char a_print[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *funargs;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang int isptrfun;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dp == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "interface = %s\n",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (dp->d_name) ? dp->d_name : "<null>");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang isptrfun = type_IsPtrFun(dp->d_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (type_IsFunction(dp->d_type) || isptrfun)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_GetTraceInfo(dp, f_type, f_print, &funargs);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang else
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "return type = %s\n", f_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "print function = %s\n", f_print);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (isptrfun)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "function is function pointer\n");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (type_IsVarargs(dp->d_type))
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "function is varargs\n");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (funargs) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang snprintf(a_type, BUFSIZ, "%s ",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_ToString(buf, funargs->d_ds));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang snprintf(a_print, BUFSIZ, "%s",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang de_const(declspec_ToString(buf, funargs->d_ds)));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = funargs->d_type;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->t_dt == DD_PTR || tp->t_dt == DD_ARY) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(a_type, "*");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(a_print, "_P");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (funargs->d_name) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang snprintf(a_name, BUFSIZ, "%s",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang funargs->d_name ? funargs->d_name : "<nil>");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "arg name = %s\n", a_name);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "arg type = %s\n", a_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "print function = %s\n", a_print);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcpy(a_name, "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcpy(a_print, "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang fprintf(stderr, "arg type = %s\n", a_type);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang funargs = funargs->d_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif /* TRACE */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang#endif /* DEBUG */
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangstatic char *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangde_const(char *str)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang{
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (str);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangvoid
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_GetTraceInfo(decl_t *dp, char *f_type, char *f_print, decl_t **funargs)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang{
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (dp == NULL)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang snprintf(f_type, BUFSIZ, "%s ",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang declspec_ToString(buf, dp->d_ds));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang snprintf(f_print, BUFSIZ, "%s",
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang de_const(declspec_ToString(buf, dp->d_ds)));
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = dp->d_type;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->t_dt == DD_PTR) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(f_type, "*");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(f_print, "*");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcat(f_type, "%s");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = decl_GetType(dp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (type_IsPtrFun(tp)) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp->t_dt != DD_FUN)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *funargs = tp->t_args;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang } else {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang *funargs = dp->d_type->t_args;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangchar *
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fangdecl_ToFormal(decl_t *dp)
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang{
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char tmp[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang static char bufp[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char *bend;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang type_t *tp = dp->d_type;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tmp[0] = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bufp[0] = 0;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = bufp;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang while (tp) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang switch (tp->t_dt) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_ARY:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "%s[%s]", tmp,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang (tp->t_sizestr)? tp->t_sizestr : "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang case DD_FUN:
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->t_args != NULL) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang char buf2[BUFSIZ];
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_t *argp = tp->t_args;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = char_getend(bufp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang for (argp = tp->t_args; argp; /* noinc */) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang decl_ToString(buf2, DTS_DECL, argp,
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang NULL);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bend, " %s", buf2);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = char_getend(bend);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (argp = argp->d_next) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bend, ",");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = char_getend(bend);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang if (tp->t_ellipsis) {
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bend, ", ...");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang bend = char_getend(bend);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bend, "");
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang break;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang tp = tp->t_next;
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang strcpy(tmp, bufp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang }
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang sprintf(bufp, "%s", tmp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang return (bufp);
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang}
22a84b8d79248a611e4ba663a268d3c4bed054acQuaker Fang