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 /*****************************************************************************/
47 /*****************************************************************************/
49 /*****************************************************************************/
54 static const char* const AttrNames [atCount] = {
60 /*****************************************************************************/
62 /*****************************************************************************/
66 static attrib_t FindAttribute (const char* Attr)
67 /* Search the attribute and return the corresponding attribute constant.
68 * Return atNone if the attribute name is not known.
73 /* For now do a linear search */
74 for (A = 0; A < atCount; ++A) {
75 if (strcmp (Attr, AttrNames[A]) == 0) {
87 static void AliasAttrib (const Declaration* D, DeclAttr* A)
88 /* Handle the "alias" attribute */
95 /* The next identifier is the name of the alias symbol */
96 if (CurTok.Tok != TOK_IDENT) {
97 Error ("Identifier expected");
101 /* Lookup the symbol for this name, it must exist */
102 Sym = FindSym (CurTok.Ident);
104 Error ("Unknown identifier: `%s'", CurTok.Ident);
109 /* Since we have the symbol entry now, skip the name */
112 /* Check if the types of the symbols are identical */
113 if (TypeCmp (D->Type, Sym->Type) < TC_EQUAL) {
114 /* Types are not identical */
115 Error ("Incompatible types");
119 /* Attribute is verified, set the stuff in the attribute description */
120 A->AttrType = atAlias;
126 void ParseAttribute (const Declaration* D, DeclAttr* A)
127 /* Parse an additional __attribute__ modifier */
132 /* Initialize the attribute description with "no attribute" */
133 A->AttrType = atNone;
135 /* Do we have an attribute? */
136 if (CurTok.Tok != TOK_ATTRIBUTE) {
137 /* No attribute, bail out */
141 /* Skip the attribute token */
144 /* Expect two(!) open braces */
148 /* Identifier follows */
149 if (CurTok.Tok != TOK_IDENT) {
150 Error ("Identifier expected");
151 /* We should *really* try to recover here, but for now: */
155 /* Map the attribute name to its id, then skip the identifier */
156 strcpy (AttrName, CurTok.Ident);
157 AttrType = FindAttribute (AttrName);
160 /* Handle possible attributes */
168 /* Attribute not known, maybe typo */
169 Error ("Illegal attribute: `%s'", AttrName);
173 /* Read the two closing braces */