diff options
author | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-10 17:41:04 +0000 |
---|---|---|
committer | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-10 17:41:04 +0000 |
commit | fb14de5a0b5a26cca9329a7fc63a8a90b1789bc1 (patch) | |
tree | a93f39fabbb674c08b5ef56b95e6fda491c70830 /usr.bin | |
parent | 21934acb9bcca96a2f98f0e85f3315a7160d87a1 (diff) |
Back out all gcc attribute parsing changes until we can do this the right
way some day. The effect of __attribute__ on a LALR C grammar is just too
ugly to fix quicklly.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/xlint/lint1/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/attr.c | 122 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/cgram.y | 103 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/externs1.h | 14 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/lint1.h | 22 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/scan.l | 45 |
6 files changed, 32 insertions, 278 deletions
diff --git a/usr.bin/xlint/lint1/Makefile b/usr.bin/xlint/lint1/Makefile index ccbe846cc44..4345ae5e31b 100644 --- a/usr.bin/xlint/lint1/Makefile +++ b/usr.bin/xlint/lint1/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.7 2005/12/07 01:55:12 cloder Exp $ +# $OpenBSD: Makefile,v 1.8 2005/12/10 17:41:03 cloder Exp $ # $NetBSD: Makefile,v 1.3 1995/07/04 01:53:05 cgd Exp $ PROG= lint1 SRCS= cgram.c scan.c mem1.c mem.c err.c main1.c decl.c tree.c func.c \ - init.c emit.c emit1.c attr.c + init.c emit.c emit1.c NOMAN= LDADD+= -ll DPADD+= ${LIBL} diff --git a/usr.bin/xlint/lint1/attr.c b/usr.bin/xlint/lint1/attr.c deleted file mode 100644 index fa4ce2aad1a..00000000000 --- a/usr.bin/xlint/lint1/attr.c +++ /dev/null @@ -1,122 +0,0 @@ -/* $OpenBSD: attr.c,v 1.2 2005/12/07 02:11:26 cloder Exp $ */ - -/* - * Copyright (c) 2005 Chad Loder - * All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef lint -static char rcsid[] = "$OpenBSD: attr.c,v 1.2 2005/12/07 02:11:26 cloder Exp $"; -#endif - -#include "lint1.h" - -attr_t -getattr(const char *attr) -{ - if (attr == NULL) - return AT_UNKNOWN; - - if (!strcmp(attr, "__noreturn__")) { - return AT_NORETURN; - } - else if (!strcmp(attr, "noreturn")) - return AT_NORETURN; - - return AT_UNKNOWN; -} - -attr_t -getqualattr(tqual_t q) -{ - if (q == VOLATILE) - return AT_VOLATILE; - - return AT_UNKNOWN; -} - -attrnode_t* -newattrnode(attr_t a) -{ - attrnode_t *an = xcalloc(1, sizeof(attrnode_t)); - an->an_attr = a; - return an; -} - -void -appendattr(attrnode_t *an, attr_t a) -{ - attrnode_t *nxt; - - while (nxt != NULL) { - nxt = an->an_nxt; - if (nxt) - an = nxt; - } - - an->an_nxt = newattrnode(a); -} - -void -appendattrnode(attrnode_t *an, attrnode_t *apn) -{ - attrnode_t *nxt; - - while (nxt != NULL) { - nxt = an->an_nxt; - if (nxt) - an = nxt; - } - - an->an_nxt = apn; -} - -void -addattr(type_t *t, attrnode_t *an) -{ - if (t->t_attr == NULL) - t->t_attr = an; - else - appendattrnode(t->t_attr, an); -} - -int -hasattr(type_t *t, attr_t a) -{ - attrnode_t *an = t->t_attr; - - while (an != NULL) { - if (an->an_attr == a) - return 1; - - an = an->an_nxt; - } - - while (t != NULL) { - t = t->t_subt; - } - - return 0; -} diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index 7cc8c8db4b9..176bdb11dcc 100644 --- a/usr.bin/xlint/lint1/cgram.y +++ b/usr.bin/xlint/lint1/cgram.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: cgram.y,v 1.15 2005/12/07 01:55:12 cloder Exp $ */ +/* $OpenBSD: cgram.y,v 1.16 2005/12/10 17:41:03 cloder Exp $ */ /* $NetBSD: cgram.y,v 1.8 1995/10/02 17:31:35 jpo Exp $ */ /* @@ -34,7 +34,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: cgram.y,v 1.15 2005/12/07 01:55:12 cloder Exp $"; +static char rcsid[] = "$OpenBSD: cgram.y,v 1.16 2005/12/10 17:41:03 cloder Exp $"; #endif #include <stdlib.h> @@ -71,8 +71,6 @@ static void ignuptorp(void); scl_t y_scl; tspec_t y_tspec; tqual_t y_tqual; - attr_t y_attr; - attrnode_t *y_attrnode; type_t *y_type; tnode_t *y_tnode; strg_t *y_strg; @@ -112,9 +110,6 @@ static void ignuptorp(void); /* qualifiers (const, volatile, restrict) */ %token <y_tqual> T_QUAL -/* attributes (noreturn, format, etc.) */ -%token <y_attr> T_ATTR - /* struct or union */ %token <y_tspec> T_SOU @@ -214,10 +209,6 @@ static void ignuptorp(void); %type <y_strg> string %type <y_strg> string2 -%type <y_attr> attribute_name -%type <y_attr> attribute_spec -%type <y_attrnode> attribute_specs -%type <y_attrnode> opt_attribute_specs %% @@ -315,7 +306,7 @@ data_def: T_SEMI warning(2); } } - | declspecs deftyp type_init_decls T_SEMI + | declspecs deftyp type_init_decls opt_attribute_spec T_SEMI | error T_SEMI { globclup(); } @@ -350,6 +341,11 @@ func_def: } ; +opt_attribute_spec: + /* empty */ + | T_ATTRIBUTE T_LPARN T_LPARN read_until_rparn T_RPARN + ; + func_decl: clrtyp deftyp notype_decl { $$ = $3; @@ -464,7 +460,6 @@ declmods: | clrtyp T_SCLASS { addscl($2); } - | clrtyp attribute_spec | declmods declmod ; @@ -475,56 +470,6 @@ declmod: | T_SCLASS { addscl($1); } - | attribute_spec - ; - -attribute_name: - T_QUAL { - $$ = getkwattr(T_QUAL, $1); - } - | T_SCLASS { - $$ = getkwattr(T_SCLASS, $1); - } - | T_TYPENAME { - $$ = getattr($1->sb_name); - } - | T_NAME { - $$ = getattr($1->sb_name); - } - ; - -attribute_spec: - T_ATTRIBUTE T_LPARN T_LPARN attribute_name T_RPARN T_RPARN { - $$ = $4; - } - | T_ATTRIBUTE T_LPARN T_LPARN attribute_name T_COMMA read_until_rparn T_RPARN { - /* some other exotic syntax that we don't understand */ - $$ = AT_UNKNOWN; - } - | T_ATTRIBUTE T_LPARN T_LPARN attribute_name T_LPARN read_until_rparn T_RPARN T_RPARN { - /* some other exotic syntax that we don't understand */ - $$ = AT_UNKNOWN; - } - ; - -attribute_specs: - attribute_spec { - /*$$ = newattrnode($1);*/ - $$ = NULL; - } - | attribute_specs attribute_spec { - /*appendattr($1, $2);*/ - $$ = $1; - } - ; - -opt_attribute_specs: - /* EMPTY */ { - $$ = NULL; - } - | attribute_specs { - $$ = $1; - } ; clrtyp_typespec: @@ -634,10 +579,10 @@ member_declaration_list_with_rbrace: ; member_declaration_list: - member_declaration opt_attribute_specs { + member_declaration { $$ = $1; } - | member_declaration_list T_SEMI member_declaration opt_attribute_specs { + | member_declaration_list T_SEMI member_declaration { $$ = lnklst($1, $3); } ; @@ -847,7 +792,7 @@ type_init_decls: ; notype_init_decl: - notype_decl opt_asm_spec { + notype_decl opt_attribute_spec opt_asm_spec { idecl($1, 0); chksz($1); } @@ -871,10 +816,10 @@ type_init_decl: ; notype_decl: - notype_direct_decl opt_attribute_specs { + notype_direct_decl { $$ = $1; } - | pointer notype_direct_decl opt_attribute_specs { + | pointer notype_direct_decl { $$ = addptr($2, $1); } ; @@ -900,10 +845,10 @@ notype_direct_decl: ; type_decl: - type_direct_decl opt_attribute_specs { + type_direct_decl { $$ = $1; } - | pointer type_direct_decl opt_attribute_specs { + | pointer type_direct_decl { $$ = addptr($2, $1); } ; @@ -994,17 +939,17 @@ direct_notype_param_decl: ; pointer: - asterisk opt_attribute_specs { + asterisk { $$ = $1; } - | asterisk opt_attribute_specs type_qualifier_list { - $$ = mergepq($1, $3); + | asterisk type_qualifier_list { + $$ = mergepq($1, $2); } - | asterisk opt_attribute_specs pointer { - $$ = mergepq($1, $3); + | asterisk pointer { + $$ = mergepq($1, $2); } - | asterisk opt_attribute_specs type_qualifier_list pointer { - $$ = mergepq(mergepq($1, $3), $4); + | asterisk type_qualifier_list pointer { + $$ = mergepq(mergepq($1, $2), $3); } ; @@ -1105,10 +1050,10 @@ vararg_parameter_type_list: ; parameter_type_list: - parameter_declaration opt_attribute_specs opt_asm_spec { + parameter_declaration opt_asm_spec { $$ = $1; } - | parameter_type_list T_COMMA parameter_declaration opt_attribute_specs opt_asm_spec { + | parameter_type_list T_COMMA parameter_declaration opt_asm_spec { $$ = lnklst($1, $3); } ; diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index 66d81b2b6df..c65d9d5c1af 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: externs1.h,v 1.4 2005/12/07 01:55:12 cloder Exp $ */ +/* $OpenBSD: externs1.h,v 1.5 2005/12/10 17:41:03 cloder Exp $ */ /* $NetBSD: externs1.h,v 1.7 1995/10/02 17:31:39 jpo Exp $ */ /* @@ -72,7 +72,6 @@ extern pos_t csrc_pos; extern symt_t symtyp; extern FILE *yyin; extern u_quad_t qbmasks[], qlmasks[], qumasks[]; -attr_t getkwattr(int, int); extern void initscan(void); extern int sign(quad_t, tspec_t, int); @@ -261,17 +260,6 @@ extern void protolib(int); extern void longlong(int); /* - * attr.c - */ -extern attr_t getattr(const char *); -extern attr_t getqualattr(tqual_t); -extern attrnode_t *newattrnode(attr_t); -extern void appendattr(attrnode_t*, attr_t); -extern void appendattrnode(attrnode_t*, attrnode_t*); -extern void addattr(type_t *, attrnode_t*); -extern int hasattr(type_t *, attr_t); - -/* * init.c */ extern int initerr; diff --git a/usr.bin/xlint/lint1/lint1.h b/usr.bin/xlint/lint1/lint1.h index b752cb41938..b4b4aed8d0c 100644 --- a/usr.bin/xlint/lint1/lint1.h +++ b/usr.bin/xlint/lint1/lint1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lint1.h,v 1.9 2005/12/09 03:13:08 cloder Exp $ */ +/* $OpenBSD: lint1.h,v 1.10 2005/12/10 17:41:03 cloder Exp $ */ /* $NetBSD: lint1.h,v 1.6 1995/10/02 17:31:41 jpo Exp $ */ /* @@ -70,28 +70,13 @@ typedef enum { } tqual_t; /* - * attributes - */ -typedef enum { - AT_UNKNOWN, AT_NORETURN, AT_VOLATILE -} attr_t; - -/* - * A node in an attribute list. - */ -typedef struct attrnode { - attr_t an_attr; - struct attrnode *an_nxt; -} attrnode_t; - -/* * Integer and floating point values are stored in this structure */ typedef struct { tspec_t v_tspec; - tspec_t v_lspec; /* the underlying type of a literal */ int v_ansiu; /* set if an integer constant is unsigned in ANSI C */ + tspec_t v_lspec; /* the underlying type of a literal */ union { quad_t _v_quad; /* integers */ ldbl_t _v_ldbl; /* floats */ @@ -155,7 +140,6 @@ typedef struct type { u_int _t_foffs : 24; /* offset of bit-field */ } _t_u; } t_u; - struct attrnode *t_attr; /* attributes */ struct type *t_subt; /* element type (arrays), return value (functions), or type pointer points to */ } type_t; @@ -237,7 +221,6 @@ typedef struct sym { enum_t *_s_et; /* tag, if it is a enumerator */ tspec_t _s_tsp; /* type (only for keywords) */ tqual_t _s_tqu; /* qualifier (only for keywords) */ - attr_t _s_att; /* attribute (only for keywords) */ struct sym *_s_args; /* arguments in old style function definitions */ } u; @@ -252,7 +235,6 @@ typedef struct sym { #define s_etyp u._s_et #define s_tspec u._s_tsp #define s_tqual u._s_tqu -#define s_attr u._s_att #define s_args u._s_args /* diff --git a/usr.bin/xlint/lint1/scan.l b/usr.bin/xlint/lint1/scan.l index c154c8cc321..b3b251bb29e 100644 --- a/usr.bin/xlint/lint1/scan.l +++ b/usr.bin/xlint/lint1/scan.l @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: scan.l,v 1.22 2005/12/09 03:13:08 cloder Exp $ */ +/* $OpenBSD: scan.l,v 1.23 2005/12/10 17:41:03 cloder Exp $ */ /* $NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $ */ /* @@ -34,7 +34,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: scan.l,v 1.22 2005/12/09 03:13:08 cloder Exp $"; +static char rcsid[] = "$OpenBSD: scan.l,v 1.23 2005/12/10 17:41:03 cloder Exp $"; #endif #include <stdlib.h> @@ -184,14 +184,13 @@ static struct kwtab { scl_t kw_scl; /* storage class if kw_token T_SCLASS */ tspec_t kw_tspec; /* type spec. if kw_token T_TYPE or T_SOU */ tqual_t kw_tqual; /* type qual. if kw_token T_QUAL */ - } kw_u; + }; u_int kw_stdc : 1; /* STDC keyword */ u_int kw_gcc : 1; /* GCC keyword */ } kwtab[] = { { "asm", T_ASM, { 0 }, 0, 1 }, { "__asm", T_ASM, { 0 }, 0, 0 }, { "__asm__", T_ASM, { 0 }, 0, 0 }, - { "__attribute", T_ATTRIBUTE, { 0 }, 0, 0 }, { "__attribute__", T_ATTRIBUTE, { 0 }, 0, 0 }, { "auto", T_SCLASS, { AUTO }, 0, 0 }, { "break", T_BREAK, { 0 }, 0, 0 }, @@ -240,10 +239,6 @@ static struct kwtab { { NULL, 0, { 0 }, 0, 0 } }; -#define kw_scl kw_u.kw_scl -#define kw_tspec kw_u.kw_tspec -#define kw_tqual kw_u.kw_tqual - /* Symbol table */ static sym_t *symtab[HSHSIZ1]; @@ -1413,37 +1408,3 @@ freeyyv(void *sp, int tok) free(strg); } } - -/* - * Return the corresponding attr_t constant for a particular C keyword, - * or AT_UNKNOWN if not known. - */ -attr_t -getkwattr(int tok, int val) -{ - struct kwtab *kw; - int eq; - - eq = 0; - for (kw = kwtab; !eq && kw->kw_name != NULL; kw++) { - if (kw->kw_token == tok) { - switch (tok) { - case T_QUAL: - eq = (val == kw->kw_tqual); - break; - case T_TYPE: - case T_SOU: - eq = (val == kw->kw_tspec); - break; - case T_SCLASS: - eq = (val == kw->kw_scl); - break; - } - - if (eq) - return getattr(kw->kw_name); - } - } - - return AT_UNKNOWN; -} |