1 /*****************************************************************************/
9 /* (C) 2003-2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
59 /* Handle the .ENUM command */
63 ExprNode* BaseExpr = GenLiteral0 ();
65 /* Check for a name */
66 int Anon = (CurTok.Tok != TOK_IDENT);
68 /* Enter a new scope, then skip the name */
69 SymEnterLevel (&CurTok.SVal, ST_ENUM, ADDR_SIZE_ABS, 0);
73 /* Test for end of line */
76 /* Read until end of struct */
77 while (CurTok.Tok != TOK_ENDENUM && CurTok.Tok != TOK_EOF) {
83 /* Skip empty lines */
84 if (CurTok.Tok == TOK_SEP) {
89 /* The format is "identifier [ = value ]" */
90 if (CurTok.Tok != TOK_IDENT) {
91 /* Maybe it's a conditional? */
92 if (!CheckConditionals ()) {
93 ErrorSkip ("Identifier expected");
98 /* We have an identifier. Is it a macro? */
99 if ((M = FindMacro (&CurTok.SVal)) != 0) {
104 /* We have an identifier, generate a symbol */
105 Sym = SymFind (CurrentScope, &CurTok.SVal, SYM_ALLOC_NEW);
107 /* Skip the member name */
110 /* Check for an assignment */
111 if (CurTok.Tok == TOK_EQ) {
113 /* Skip the equal sign */
116 /* Read the new expression */
117 EnumExpr = Expression ();
119 /* Reset the base expression and the offset */
121 BaseExpr = CloneExpr (EnumExpr);
126 /* No assignment, use last value + 1 */
127 EnumExpr = GenAddExpr (CloneExpr (BaseExpr), GenLiteralExpr (Offs));
131 /* Assign the value to the enum member */
132 SymDef (Sym, EnumExpr, ADDR_SIZE_DEFAULT, SF_NONE);
134 /* Increment the offset for the next member */
137 /* Expect end of line */
141 /* If this is not an anon enum, leave its scope */
143 /* Close the enum scope */
147 /* End of enum definition */
148 Consume (TOK_ENDENUM, "`.ENDENUM' expected");
150 /* Free the base expression */