1 /*-------------------------------------------------------------------------
2 SDCCattr.h - Code file for attributes.
4 Copyright (c) 2021 Philipp Klaus Krause pkk@spth.de
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 -------------------------------------------------------------------------*/
26 attribute
*newAttribute(const symbol
*token_sym
, const char *argument_clause
)
28 const char *token_string
, *token_string_prefix
;
30 attribute
*attr
= Safe_alloc (sizeof (attribute
));
38 token_string
= token_sym
->next
->name
;
39 token_string_prefix
= token_sym
->name
;
43 token_string
= token_sym
->name
;
44 token_string_prefix
= 0;
47 wassert(token_string
);
48 strncpyz (attr
->token_string
, token_string
, sizeof (attr
->token_string
));
50 if (!token_string_prefix
)
52 if(!strcmp(token_string
, "nodiscard") || !strcmp(token_string
, "__nodiscard__"))
53 attr
->token
= ATTRIBUTE_NODISCARD
;
54 else if(!strcmp(token_string
, "maybe_unused") || !strcmp(token_string
, "__maybe_unused__"))
55 attr
->token
= ATTRIBUTE_MAYBE_UNUSED
;
56 else if(!strcmp(token_string
, "deprecated") || !strcmp(token_string
, "__deprecated__"))
57 attr
->token
= ATTRIBUTE_DEPRECATED
;
58 else if(!strcmp(token_string
, "fallthrough") || !strcmp(token_string
, "__fallthrough__"))
59 attr
->token
= ATTRIBUTE_FALLTHROUGH
;
60 else // Unknown standard attribute
61 attr
->token
= ATTRIBUTE_OTHER
;
63 else if(!strcmp(token_string_prefix
, "sdcc")) // SDCC implementation-specific attribute
65 attr
->token
= ATTRIBUTE_OTHER
;
67 else // Unknown-implementation implementation-specific unknown attribute.
68 attr
->token
= ATTRIBUTE_OTHER
;