--- /dev/null
+/*****************************************************************************/
+/* */
+/* enum.c */
+/* */
+/* .ENUM command */
+/* */
+/* */
+/* */
+/* (C) 2003 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
+/* */
+/* */
+/* This software is provided 'as-is', without any expressed or implied */
+/* warranty. In no event will the authors be held liable for any damages */
+/* arising from the use of this software. */
+/* */
+/* Permission is granted to anyone to use this software for any purpose, */
+/* including commercial applications, and to alter it and redistribute it */
+/* freely, subject to the following restrictions: */
+/* */
+/* 1. The origin of this software must not be misrepresented; you must not */
+/* claim that you wrote the original software. If you use this software */
+/* in a product, an acknowledgment in the product documentation would be */
+/* appreciated but is not required. */
+/* 2. Altered source versions must be plainly marked as such, and must not */
+/* be misrepresented as being the original software. */
+/* 3. This notice may not be removed or altered from any source */
+/* distribution. */
+/* */
+/*****************************************************************************/
+
+
+
+/* common */
+#include "addrsize.h"
+
+/* ca65 */
+#include "enum.h"
+#include "error.h"
+#include "expr.h"
+#include "nexttok.h"
+#include "scanner.h"
+#include "symbol.h"
+#include "symtab.h"
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+void DoEnum (void)
+/* Handle the .ENUM command */
+{
+ /* Start at zero */
+ ExprNode* NextExpr = GenLiteralExpr (0);
+
+ /* Check for a name */
+ int Anon = (Tok != TOK_IDENT);
+ if (!Anon) {
+ /* Enter a new scope, then skip the name */
+ SymEnterLevel (SVal, ST_ENUM, ADDR_SIZE_ABS);
+ NextTok ();
+ }
+
+ /* Test for end of line */
+ ConsumeSep ();
+
+ /* Read until end of struct */
+ while (Tok != TOK_ENDENUM && Tok != TOK_EOF) {
+
+ SymEntry* Sym;
+ ExprNode* EnumExpr;
+
+
+ /* The format is "identifier [ = value ]" */
+ if (Tok != TOK_IDENT) {
+ ErrorSkip ("Identifier expected");
+ continue;
+ }
+
+ /* We have an identifier, generate a symbol */
+ Sym = SymFind (CurrentScope, SVal, SYM_ALLOC_NEW);
+
+ /* Skip the member name */
+ NextTok ();
+
+ /* Check for an assignment */
+ if (Tok == TOK_EQ) {
+
+ /* Skip the equal sign */
+ NextTok ();
+
+ /* Delete the old next expression */
+ FreeExpr (NextExpr);
+
+ /* Read the new one */
+ EnumExpr = Expression ();
+
+ } else {
+
+ EnumExpr = NextExpr;
+
+ }
+
+ /* Generate the next expression from the current one */
+ NextExpr = GenAddExpr (CloneExpr (EnumExpr), GenLiteralExpr (1));
+ NextExpr = SimplifyExpr (NextExpr);
+
+ /* Assign the value to the enum member */
+ SymDef (Sym, EnumExpr, ADDR_SIZE_DEFAULT, SF_NONE);
+
+ /* Expect end of line */
+ ConsumeSep ();
+ }
+
+ /* If this is not an anon enum, leave its scope */
+ if (!Anon) {
+ /* Close the enum scope */
+ SymLeaveLevel ();
+ }
+
+ /* End of enum definition */
+ Consume (TOK_ENDENUM, "`.ENDENUM' expected");
+
+ /* Free the last (unused) enum expression */
+ FreeExpr (NextExpr);
+}
+
+
+
--- /dev/null
+/*****************************************************************************/
+/* */
+/* enum.h */
+/* */
+/* .ENUM command */
+/* */
+/* */
+/* */
+/* (C) 2003 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
+/* */
+/* */
+/* This software is provided 'as-is', without any expressed or implied */
+/* warranty. In no event will the authors be held liable for any damages */
+/* arising from the use of this software. */
+/* */
+/* Permission is granted to anyone to use this software for any purpose, */
+/* including commercial applications, and to alter it and redistribute it */
+/* freely, subject to the following restrictions: */
+/* */
+/* 1. The origin of this software must not be misrepresented; you must not */
+/* claim that you wrote the original software. If you use this software */
+/* in a product, an acknowledgment in the product documentation would be */
+/* appreciated but is not required. */
+/* 2. Altered source versions must be plainly marked as such, and must not */
+/* be misrepresented as being the original software. */
+/* 3. This notice may not be removed or altered from any source */
+/* distribution. */
+/* */
+/*****************************************************************************/
+
+
+
+#ifndef ENUM_H
+#define ENUM_H
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+void DoEnum (void);
+/* Handle the .ENUM command */
+
+
+
+/* End of enum.h */
+
+#endif
+
+
+
-static ExprNode* SimplifyExpr (ExprNode* Expr)
-/* Try to simplify the given expression tree */
-{
- if (Expr && Expr->Op != EXPR_LITERAL) {
-
- /* Create an expression description and initialize it */
- ExprDesc D;
- InitExprDesc (&D);
-
- /* Study the expression */
- StudyExpr (Expr, &D, 1);
-
- /* Now check if we can generate a literal value */
- if (ExprDescIsConst (&D)) {
- /* No external references */
- FreeExpr (Expr);
- Expr = GenLiteralExpr (D.Val);
- }
- }
- return Expr;
-}
-
-
-
ExprNode* Expression (void)
/* Evaluate an expression, build the expression tree on the heap and return
* a pointer to the root of the tree.
+ExprNode* SimplifyExpr (ExprNode* Expr)
+/* Try to simplify the given expression tree */
+{
+ if (Expr && Expr->Op != EXPR_LITERAL) {
+
+ /* Create an expression description and initialize it */
+ ExprDesc D;
+ InitExprDesc (&D);
+
+ /* Study the expression */
+ StudyExpr (Expr, &D, 1);
+
+ /* Now check if we can generate a literal value */
+ if (ExprDescIsConst (&D)) {
+ /* No external references */
+ FreeExpr (Expr);
+ Expr = GenLiteralExpr (D.Val);
+ }
+ }
+ return Expr;
+}
+
+
+
ExprNode* GenLiteralExpr (long Val)
/* Return an expression tree that encodes the given literal value */
{
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
void FreeExpr (ExprNode* Root);
/* Free the expression tree, Root is pointing to. */
-ExprNode* GenLiteralExpr (long Val);
+ExprNode* SimplifyExpr (ExprNode* Expr);
+/* Try to simplify the given expression tree */
+
+ExprNode* GenLiteralExpr (long Val);
/* Return an expression tree that encodes the given literal value */
ExprNode* GenSymExpr (struct SymEntry* Sym);
condasm.o \
dbginfo.o \
ea.o \
+ enum.o \
error.o \
expr.o \
feature.o \
condasm.obj \
dbginfo.obj \
ea.obj \
+ enum.obj \
error.obj \
expr.obj \
feature.obj \
#include "asserts.h"
#include "condasm.h"
#include "dbginfo.h"
+#include "enum.h"
#include "error.h"
#include "expr.h"
#include "feature.h"
{ ccKeepToken, DoConditionals }, /* .ELSE */
{ ccKeepToken, DoConditionals }, /* .ELSEIF */
{ ccKeepToken, DoEnd },
+ { ccNone, DoUnexpected }, /* .ENDENUM */
{ ccKeepToken, DoConditionals }, /* .ENDIF */
{ ccNone, DoUnexpected }, /* .ENDMACRO */
{ ccNone, DoEndProc },
{ ccNone, DoEndScope },
{ ccNone, DoUnexpected }, /* .ENDSTRUCT */
{ ccNone, DoUnexpected }, /* .ENDUNION */
+ { ccNone, DoEnum },
{ ccNone, DoError },
{ ccNone, DoExitMacro },
{ ccNone, DoExport },
{ ".ELSE", TOK_ELSE },
{ ".ELSEIF", TOK_ELSEIF },
{ ".END", TOK_END },
+ { ".ENDENUM", TOK_ENDENUM },
{ ".ENDIF", TOK_ENDIF },
{ ".ENDMAC", TOK_ENDMACRO },
{ ".ENDMACRO", TOK_ENDMACRO },
{ ".ENDSCOPE", TOK_ENDSCOPE },
{ ".ENDSTRUCT", TOK_ENDSTRUCT },
{ ".ENDUNION", TOK_ENDUNION },
+ { ".ENUM", TOK_ENUM },
{ ".ERROR", TOK_ERROR },
{ ".EXITMAC", TOK_EXITMACRO },
{ ".EXITMACRO", TOK_EXITMACRO },
TOK_DWORD,
TOK_ELSE,
TOK_ELSEIF,
- TOK_END,
+ TOK_END,
+ TOK_ENDENUM,
TOK_ENDIF,
TOK_ENDMACRO,
TOK_ENDPROC,
TOK_ENDSCOPE,
TOK_ENDSTRUCT,
TOK_ENDUNION,
+ TOK_ENUM,
TOK_ERROR,
TOK_EXITMACRO,
TOK_EXPORT,
/* */
/* struct.c */
/* */
-/* .STRUCT command */
+/* .STRUCT/.UNION commands */
/* */
/* */
/* */
/* */
/* struct.h */
/* */
-/* .STRUCT command */
+/* .STRUCT/.UNION commands */
/* */
/* */
/* */
#define ST_GLOBAL 0x00 /* Root level */
#define ST_PROC 0x01 /* .PROC */
#define ST_SCOPE 0x02 /* .SCOPE */
-#define ST_STRUCT 0x03 /* .STRUCT */
-#define ST_UNION 0x04 /* .UNION */
+#define ST_STRUCT 0x03 /* .STRUCT/.UNION */
+#define ST_ENUM 0x04 /* .ENUM */
#define ST_UNDEF 0xFF
/* A symbol table */