1 /*****************************************************************************/
5 /* Declaration attributes */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
45 /*****************************************************************************/
47 /*****************************************************************************/
52 static const char* const AttrNames [atCount] = {
58 /*****************************************************************************/
60 /*****************************************************************************/
64 static attrib_t FindAttribute (const char* Attr)
65 /* Search the attribute and return the corresponding attribute constant.
66 * Return atNone if the attribute name is not known.
71 /* For now do a linear search */
72 for (A = 0; A < atCount; ++A) {
73 if (strcmp (Attr, AttrNames[A]) == 0) {
85 static void AliasAttrib (const Declaration* D, DeclAttr* A)
86 /* Handle the "alias" attribute */
93 /* The next identifier is the name of the alias symbol */
94 if (CurTok.Tok != TOK_IDENT) {
95 Error ("Identifier expected");
99 /* Lookup the symbol for this name, it must exist */
100 Sym = FindSym (CurTok.Ident);
102 Error ("Unknown identifier: `%s'", CurTok.Ident);
107 /* Since we have the symbol entry now, skip the name */
110 /* Check if the types of the symbols are identical */
111 if (TypeCmp (D->Type, Sym->Type) < TC_EQUAL) {
112 /* Types are not identical */
113 Error ("Incompatible types");
117 /* Attribute is verified, set the stuff in the attribute description */
118 A->AttrType = atAlias;
124 void ParseAttribute (const Declaration* D, DeclAttr* A)
125 /* Parse an additional __attribute__ modifier */
130 /* Initialize the attribute description with "no attribute" */
131 A->AttrType = atNone;
133 /* Do we have an attribute? */
134 if (CurTok.Tok != TOK_ATTRIBUTE) {
135 /* No attribute, bail out */
139 /* Skip the attribute token */
142 /* Expect two(!) open braces */
146 /* Identifier follows */
147 if (CurTok.Tok != TOK_IDENT) {
148 Error ("Identifier expected");
149 /* We should *really* try to recover here, but for now: */
153 /* Map the attribute name to its id, then skip the identifier */
154 strcpy (AttrName, CurTok.Ident);
155 AttrType = FindAttribute (AttrName);
158 /* Handle possible attributes */
166 /* Attribute not known, maybe typo */
167 Error ("Illegal attribute: `%s'", AttrName);
171 /* Read the two closing braces */