Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 Handle the rest of gcc __attribute__ s.
details: https://anonhg.NetBSD.org/src/rev/663ae4fba52a
branches: trunk
changeset: 328784:663ae4fba52a
user: christos <christos%NetBSD.org@localhost>
date: Fri Apr 18 00:23:46 2014 +0000
description:
Handle the rest of gcc __attribute__ s.
diffstat:
usr.bin/xlint/lint1/cgram.y | 26 +++++-
usr.bin/xlint/lint1/externs1.h | 3 +-
usr.bin/xlint/lint1/scan.l | 186 +++++++++++++++++++++++-----------------
3 files changed, 131 insertions(+), 84 deletions(-)
diffs (truncated from 336 to 300 lines):
diff -r 81b7c476a356 -r 663ae4fba52a usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Fri Apr 18 00:21:14 2014 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Fri Apr 18 00:23:46 2014 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.60 2014/04/17 17:29:24 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.61 2014/04/18 00:23:46 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.60 2014/04/17 17:29:24 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.61 2014/04/18 00:23:46 christos Exp $");
#endif
#include <stdlib.h>
@@ -189,11 +189,17 @@
%token <y_type> T_ATTRIBUTE
%token <y_type> T_AT_ALIGNED
%token <y_type> T_AT_DEPRECATED
+%token <y_type> T_AT_NORETURN
%token <y_type> T_AT_MAY_ALIAS
%token <y_type> T_AT_PACKED
+%token <y_type> T_AT_PURE
%token <y_type> T_AT_TUINION
%token <y_type> T_AT_TUNION
%token <y_type> T_AT_UNUSED
+%token <y_type> T_AT_FORMAT
+%token <y_type> T_AT_FORMAT_PRINTF
+%token <y_type> T_AT_FORMAT_SCANF
+%token <y_type> T_AT_FORMAT_STRFTIME
@@ -470,19 +476,33 @@
| error T_SEMI
;
+type_attribute_format_type:
+ T_AT_FORMAT_PRINTF
+ | T_AT_FORMAT_SCANF
+ | T_AT_FORMAT_STRFTIME
+ ;
+
type_attribute_spec:
T_AT_DEPRECATED
| T_AT_ALIGNED T_LPARN constant T_RPARN
| T_AT_MAY_ALIAS
+ | T_AT_NORETURN
| T_AT_PACKED {
addpacked();
}
+ | T_AT_PURE
| T_AT_TUNION
+ | T_AT_FORMAT T_LPARN type_attribute_format_type T_COMMA
+ constant T_COMMA constant T_RPARN
| T_AT_UNUSED
;
type_attribute:
- T_ATTRIBUTE T_LPARN T_LPARN type_attribute_spec T_RPARN T_RPARN
+ T_ATTRIBUTE T_LPARN T_LPARN {
+ attron = 1;
+ } type_attribute_spec {
+ attron = 0;
+ } T_RPARN T_RPARN
| T_PACKED {
addpacked();
}
diff -r 81b7c476a356 -r 663ae4fba52a usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Fri Apr 18 00:21:14 2014 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Fri Apr 18 00:23:46 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.31 2013/04/19 17:43:05 christos Exp $ */
+/* $NetBSD: externs1.h,v 1.32 2014/04/18 00:23:46 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -68,6 +68,7 @@
/*
* scan.l
*/
+extern int attron;
extern pos_t curr_pos;
extern pos_t csrc_pos;
extern symt_t symtyp;
diff -r 81b7c476a356 -r 663ae4fba52a usr.bin/xlint/lint1/scan.l
--- a/usr.bin/xlint/lint1/scan.l Fri Apr 18 00:21:14 2014 +0000
+++ b/usr.bin/xlint/lint1/scan.l Fri Apr 18 00:23:46 2014 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: scan.l,v 1.54 2014/02/18 22:01:36 christos Exp $ */
+/* $NetBSD: scan.l,v 1.55 2014/04/18 00:23:46 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: scan.l,v 1.54 2014/02/18 22:01:36 christos Exp $");
+__RCSID("$NetBSD: scan.l,v 1.55 2014/04/18 00:23:46 christos Exp $");
#endif
#include <stdlib.h>
@@ -60,6 +60,9 @@
*/
pos_t csrc_pos = { 1, "", 0 };
+/* Are we parsing a gcc attribute? */
+int attron;
+
static void incline(void);
static void badchar(int);
static sbuf_t *allocsb(void);
@@ -193,81 +196,95 @@
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. fi kw_token T_QUAL */
- u_int kw_c89; /* c89 keyword */
- u_int kw_c99; /* c99 keyword */
- u_int kw_gcc; /* GCC keyword */
+ u_int kw_c89 : 1; /* c89 keyword */
+ u_int kw_c99 : 1; /* c99 keyword */
+ u_int kw_gcc : 1; /* GCC keyword */
+ u_int kw_attr : 1; /* GCC attribute, keyword */
} kwtab[] = {
- { "__alignof__", T_ALIGNOF, 0, 0, 0, 0, 0, 0 },
- { "__attribute__",T_ATTRIBUTE, 0, 0, 0, 0, 0, 1 },
- { "attribute", T_ATTRIBUTE, 0, 0, 0, 0, 0, 1 },
- { "__packed__", T_AT_PACKED, 0, 0, 0, 0, 0, 1 },
- { "packed", T_AT_PACKED, 0, 0, 0, 0, 0, 1 },
- { "__aligned__",T_AT_ALIGNED, 0, 0, 0, 0, 0, 1 },
- { "aligned", T_AT_ALIGNED, 0, 0, 0, 0, 0, 1 },
- { "__transparent_union__",T_AT_TUNION,0,0, 0, 0, 0, 1 },
- { "transparent_union",T_AT_TUNION,0, 0, 0, 0, 0, 1 },
- { "__unused__", T_AT_UNUSED, 0, 0, 0, 0, 0, 1 },
- { "unused", T_AT_UNUSED, 0, 0, 0, 0, 0, 1 },
- { "__deprecated__",T_AT_DEPRECATED,0, 0, 0, 0, 0, 1 },
- { "deprecated", T_AT_DEPRECATED,0, 0, 0, 0, 0, 1 },
- { "__may_alias__",T_AT_MAY_ALIAS,0, 0, 0, 0, 0, 1 },
- { "may_alias", T_AT_MAY_ALIAS, 0, 0, 0, 0, 0, 1 },
- { "asm", T_ASM, 0, 0, 0, 0, 0, 1 },
- { "__asm", T_ASM, 0, 0, 0, 0, 0, 0 },
- { "__asm__", T_ASM, 0, 0, 0, 0, 0, 0 },
- { "auto", T_SCLASS, AUTO, 0, 0, 0, 0, 0 },
- { "break", T_BREAK, 0, 0, 0, 0, 0, 0 },
- { "_Bool", T_TYPE, 0, BOOL, 0, 0, 1, 0 },
- { "case", T_CASE, 0, 0, 0, 0, 0, 0 },
- { "char", T_TYPE, 0, CHAR, 0, 0, 0, 0 },
- { "const", T_QUAL, 0, 0, CONST, 1, 0, 0 },
- { "_Complex", T_TYPE, 0, COMPLEX,0, 0, 1, 0 },
- { "__const__", T_QUAL, 0, 0, CONST, 0, 0, 0 },
- { "__const", T_QUAL, 0, 0, CONST, 0, 0, 0 },
- { "continue", T_CONTINUE, 0, 0, 0, 0, 0, 0 },
- { "default", T_DEFAULT, 0, 0, 0, 0, 0, 0 },
- { "do", T_DO, 0, 0, 0, 0, 0, 0 },
- { "double", T_TYPE, 0, DOUBLE, 0, 0, 0, 0 },
- { "else", T_ELSE, 0, 0, 0, 0, 0, 0 },
- { "enum", T_ENUM, 0, 0, 0, 0, 0, 0 },
- { "__extension__", T_EXTENSION, 0, 0, 0, 0, 0, 1 },
- { "extern", T_SCLASS, EXTERN, 0, 0, 0, 0, 0 },
- { "float", T_TYPE, 0, FLOAT, 0, 0, 0, 0 },
- { "for", T_FOR, 0, 0, 0, 0, 0, 0 },
- { "goto", T_GOTO, 0, 0, 0, 0, 0, 0 },
- { "if", T_IF, 0, 0, 0, 0, 0, 0 },
- { "__imag__", T_IMAG, 0, 0, 0, 0, 1, 0 },
- { "inline", T_SCLASS, INLINE, 0, 0, 0, 1, 0 },
- { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0, 0 },
- { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0, 0 },
- { "int", T_TYPE, 0, INT, 0, 0, 0, 0 },
- { "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0, 0 },
- { "long", T_TYPE, 0, LONG, 0, 0, 0, 0 },
- { "__real__", T_REAL, 0, 0, 0, 0, 1, 0 },
- { "register", T_SCLASS, REG, 0, 0, 0, 0, 0 },
- { "restrict", T_QUAL, 0, 0, RESTRICT, 0, 1, 0 },
- { "return", T_RETURN, 0, 0, 0, 0, 0, 0 },
- { "__packed", T_PACKED, 0, 0, 0, 0, 0, 0 },
- { "short", T_TYPE, 0, SHORT, 0, 0, 0, 0 },
- { "signed", T_TYPE, 0, SIGNED, 0, 1, 0, 0 },
- { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0, 0 },
- { "__signed", T_TYPE, 0, SIGNED, 0, 0, 0, 0 },
- { "sizeof", T_SIZEOF, 0, 0, 0, 0, 0, 0 },
- { "static", T_SCLASS, STATIC, 0, 0, 0, 0, 0 },
- { "struct", T_SOU, 0, STRUCT, 0, 0, 0, 0 },
- { "switch", T_SWITCH, 0, 0, 0, 0, 0, 0 },
- { "typedef", T_SCLASS, TYPEDEF, 0, 0, 0, 0, 0 },
- { "typeof", T_TYPEOF, 0, 0, 0, 0, 0, 1 },
- { "__typeof", T_TYPEOF, 0, 0, 0, 0, 0, 1 },
- { "__typeof__", T_TYPEOF, 0, 0, 0, 0, 0, 1 },
- { "union", T_SOU, 0, UNION, 0, 0, 0, 0 },
- { "unsigned", T_TYPE, 0, UNSIGN, 0, 0, 0, 0 },
- { "void", T_TYPE, 0, VOID, 0, 0, 0, 0 },
- { "volatile", T_QUAL, 0, 0, VOLATILE, 1, 0, 0 },
- { "__volatile__", T_QUAL, 0, 0, VOLATILE, 0, 0, 0 },
- { "__volatile", T_QUAL, 0, 0, VOLATILE, 0, 0, 0 },
- { "while", T_WHILE, 0, 0, 0, 0, 0, 0 },
- { NULL, 0, 0, 0, 0, 0, 0, 0 }
+ { "__alignof__", T_ALIGNOF, 0, 0, 0, 0, 0, 0, 0 },
+ { "__attribute__",T_ATTRIBUTE, 0, 0, 0, 0, 0, 1, 0 },
+ { "attribute", T_ATTRIBUTE, 0, 0, 0, 0, 0, 1, 0 },
+ { "__packed__", T_AT_PACKED, 0, 0, 0, 0, 0, 1, 1 },
+ { "packed", T_AT_PACKED, 0, 0, 0, 0, 0, 1, 1 },
+ { "__aligned__",T_AT_ALIGNED, 0, 0, 0, 0, 0, 1, 1 },
+ { "aligned", T_AT_ALIGNED, 0, 0, 0, 0, 0, 1, 1 },
+ { "__transparent_union__",T_AT_TUNION,0,0, 0, 0, 0, 1, 1 },
+ { "transparent_union",T_AT_TUNION,0, 0, 0, 0, 0, 1, 1 },
+ { "__unused__", T_AT_UNUSED, 0, 0, 0, 0, 0, 1, 1 },
+ { "unused", T_AT_UNUSED, 0, 0, 0, 0, 0, 1, 1 },
+ { "__deprecated__",T_AT_DEPRECATED,0, 0, 0, 0, 0, 1, 1 },
+ { "deprecated", T_AT_DEPRECATED,0, 0, 0, 0, 0, 1, 1 },
+ { "__may_alias__",T_AT_MAY_ALIAS,0, 0, 0, 0, 0, 1, 1 },
+ { "may_alias", T_AT_MAY_ALIAS, 0, 0, 0, 0, 0, 1, 1 },
+ { "format", T_AT_FORMAT, 0, 0, 0, 0, 0, 1, 1 },
+ { "__format__", T_AT_FORMAT, 0, 0, 0, 0, 0, 1, 1 },
+ { "printf", T_AT_FORMAT_PRINTF,0, 0, 0, 0, 0, 1, 1 },
+ { "__printf__", T_AT_FORMAT_PRINTF,0, 0, 0, 0, 0, 1, 1 },
+ { "scanf", T_AT_FORMAT_SCANF,0, 0, 0, 0, 0, 1, 1 },
+ { "__scanf__", T_AT_FORMAT_SCANF,0, 0, 0, 0, 0, 1, 1 },
+ { "strftime", T_AT_FORMAT_SCANF,0, 0, 0, 0, 0, 1, 1 },
+ { "__strftime__",T_AT_FORMAT_STRFTIME,0,0, 0, 0, 0, 1, 1 },
+ { "pure", T_AT_PURE, 0, 0, 0, 0, 0, 1, 1 },
+ { "__pure__", T_AT_PURE, 0, 0, 0, 0, 0, 1, 1 },
+ { "noreturn", T_AT_NORETURN, 0, 0, 0, 0, 0, 1, 1 },
+ { "__noreturn__",T_AT_NORETURN, 0, 0, 0, 0, 0, 1, 1 },
+ { "asm", T_ASM, 0, 0, 0, 0, 0, 1, 1 },
+ { "__asm", T_ASM, 0, 0, 0, 0, 0, 0, 0 },
+ { "__asm__", T_ASM, 0, 0, 0, 0, 0, 0, 0 },
+ { "auto", T_SCLASS, AUTO, 0, 0, 0, 0, 0, 0 },
+ { "break", T_BREAK, 0, 0, 0, 0, 0, 0, 0 },
+ { "_Bool", T_TYPE, 0, BOOL, 0, 0, 1, 0, 0 },
+ { "case", T_CASE, 0, 0, 0, 0, 0, 0, 0 },
+ { "char", T_TYPE, 0, CHAR, 0, 0, 0, 0, 0 },
+ { "const", T_QUAL, 0, 0, CONST, 1, 0, 0, 0 },
+ { "_Complex", T_TYPE, 0, COMPLEX,0, 0, 1, 0, 0 },
+ { "__const__", T_QUAL, 0, 0, CONST, 0, 0, 0, 0 },
+ { "__const", T_QUAL, 0, 0, CONST, 0, 0, 0, 0 },
+ { "continue", T_CONTINUE, 0, 0, 0, 0, 0, 0, 0 },
+ { "default", T_DEFAULT, 0, 0, 0, 0, 0, 0, 0 },
+ { "do", T_DO, 0, 0, 0, 0, 0, 0, 0 },
+ { "double", T_TYPE, 0, DOUBLE, 0, 0, 0, 0, 0 },
+ { "else", T_ELSE, 0, 0, 0, 0, 0, 0, 0 },
+ { "enum", T_ENUM, 0, 0, 0, 0, 0, 0, 0 },
+ { "__extension__", T_EXTENSION, 0, 0, 0, 0, 0, 1, 0 },
+ { "extern", T_SCLASS, EXTERN, 0, 0, 0, 0, 0, 0 },
+ { "float", T_TYPE, 0, FLOAT, 0, 0, 0, 0, 0 },
+ { "for", T_FOR, 0, 0, 0, 0, 0, 0, 0 },
+ { "goto", T_GOTO, 0, 0, 0, 0, 0, 0, 0 },
+ { "if", T_IF, 0, 0, 0, 0, 0, 0, 0 },
+ { "__imag__", T_IMAG, 0, 0, 0, 0, 1, 0, 0 },
+ { "inline", T_SCLASS, INLINE, 0, 0, 0, 1, 0, 0 },
+ { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0, 0, 0 },
+ { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0, 0, 0 },
+ { "int", T_TYPE, 0, INT, 0, 0, 0, 0, 0 },
+ { "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0, 0, 0 },
+ { "long", T_TYPE, 0, LONG, 0, 0, 0, 0, 0 },
+ { "__real__", T_REAL, 0, 0, 0, 0, 1, 0, 0 },
+ { "register", T_SCLASS, REG, 0, 0, 0, 0, 0, 0 },
+ { "__restrict__",T_QUAL, 0, 0, RESTRICT, 0, 1, 0, 0 },
+ { "restrict", T_QUAL, 0, 0, RESTRICT, 0, 1, 0, 0 },
+ { "return", T_RETURN, 0, 0, 0, 0, 0, 0, 0 },
+ { "__packed", T_PACKED, 0, 0, 0, 0, 0, 0, 0 },
+ { "short", T_TYPE, 0, SHORT, 0, 0, 0, 0, 0 },
+ { "signed", T_TYPE, 0, SIGNED, 0, 1, 0, 0, 0 },
+ { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0, 0, 0 },
+ { "__signed", T_TYPE, 0, SIGNED, 0, 0, 0, 0, 0 },
+ { "sizeof", T_SIZEOF, 0, 0, 0, 0, 0, 0, 0 },
+ { "static", T_SCLASS, STATIC, 0, 0, 0, 0, 0, 0 },
+ { "struct", T_SOU, 0, STRUCT, 0, 0, 0, 0, 0 },
+ { "switch", T_SWITCH, 0, 0, 0, 0, 0, 0, 0 },
+ { "typedef", T_SCLASS, TYPEDEF, 0, 0, 0, 0, 0, 0 },
+ { "typeof", T_TYPEOF, 0, 0, 0, 0, 0, 1, 0 },
+ { "__typeof", T_TYPEOF, 0, 0, 0, 0, 0, 1, 0 },
+ { "__typeof__", T_TYPEOF, 0, 0, 0, 0, 0, 1, 0 },
+ { "union", T_SOU, 0, UNION, 0, 0, 0, 0, 0 },
+ { "unsigned", T_TYPE, 0, UNSIGN, 0, 0, 0, 0, 0 },
+ { "void", T_TYPE, 0, VOID, 0, 0, 0, 0, 0 },
+ { "volatile", T_QUAL, 0, 0, VOLATILE, 1, 0, 0, 0 },
+ { "__volatile__", T_QUAL, 0, 0, VOLATILE, 0, 0, 0, 0 },
+ { "__volatile", T_QUAL, 0, 0, VOLATILE, 0, 0, 0, 0 },
+ { "while", T_WHILE, 0, 0, 0, 0, 0, 0, 0 },
+ { NULL, 0, 0, 0, 0, 0, 0, 0, 0 }
};
/* Symbol table */
@@ -310,7 +327,7 @@
continue;
sym = getblk(sizeof (sym_t));
sym->s_name = kw->kw_name;
- sym->s_keyw = 1;
+ sym->s_keyw = kw;
sym->s_value.v_quad = kw->kw_token;
if (kw->kw_token == T_TYPE || kw->kw_token == T_SOU) {
sym->s_tspec = kw->kw_tspec;
@@ -347,10 +364,15 @@
if ((sb = sbfrlst) != NULL) {
Home |
Main Index |
Thread Index |
Old Index