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 /*****************************************************************************/
38 #include "scopedefs.h"
53 /*****************************************************************************/
55 /*****************************************************************************/
60 /* Handle the .ENUM command */
64 ExprNode* BaseExpr = GenLiteral0 ();
66 /* Check for a name */
67 int Anon = (CurTok.Tok != TOK_IDENT);
69 /* Enter a new scope, then skip the name */
70 SymEnterLevel (&CurTok.SVal, SCOPE_ENUM, ADDR_SIZE_ABS, 0);
74 /* Test for end of line */
77 /* Read until end of struct */
78 while (CurTok.Tok != TOK_ENDENUM && CurTok.Tok != TOK_EOF) {
84 /* Skip empty lines */
85 if (CurTok.Tok == TOK_SEP) {
90 /* The format is "identifier [ = value ]" */
91 if (CurTok.Tok != TOK_IDENT) {
92 /* Maybe it's a conditional? */
93 if (!CheckConditionals ()) {
94 ErrorSkip ("Identifier expected");
99 /* We have an identifier. Is it a macro? */
100 if ((M = FindMacro (&CurTok.SVal)) != 0) {
105 /* We have an identifier, generate a symbol */
106 Sym = SymFind (CurrentScope, &CurTok.SVal, SYM_ALLOC_NEW);
108 /* Skip the member name */
111 /* Check for an assignment */
112 if (CurTok.Tok == TOK_EQ) {
114 /* Skip the equal sign */
117 /* Read the new expression */
118 EnumExpr = Expression ();
120 /* Reset the base expression and the offset */
122 BaseExpr = CloneExpr (EnumExpr);
127 /* No assignment, use last value + 1 */
128 EnumExpr = GenAddExpr (CloneExpr (BaseExpr), GenLiteralExpr (Offs));
132 /* Assign the value to the enum member */
133 SymDef (Sym, EnumExpr, ADDR_SIZE_DEFAULT, SF_NONE);
135 /* Increment the offset for the next member */
138 /* Expect end of line */
142 /* If this is not an anon enum, leave its scope */
144 /* Close the enum scope */
148 /* End of enum definition */
149 Consume (TOK_ENDENUM, "`.ENDENUM' expected");
151 /* Free the base expression */