From bf6b0b9eb7fb25c49ebfc150f4309d6a80fbf87c Mon Sep 17 00:00:00 2001 From: uz Date: Fri, 8 Jul 2011 09:55:17 +0000 Subject: [PATCH] Check for macros within .STRUCT/.ENUM. git-svn-id: svn://svn.cc65.org/cc65/trunk@5076 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/enum.c | 8 ++++++++ src/ca65/macro.h | 8 ++++---- src/ca65/struct.c | 11 +++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ca65/enum.c b/src/ca65/enum.c index 87d0380cc..ee76e4632 100644 --- a/src/ca65/enum.c +++ b/src/ca65/enum.c @@ -41,6 +41,7 @@ #include "enum.h" #include "error.h" #include "expr.h" +#include "macro.h" #include "nexttok.h" #include "scanner.h" #include "symbol.h" @@ -75,6 +76,7 @@ void DoEnum (void) /* Read until end of struct */ while (CurTok.Tok != TOK_ENDENUM && CurTok.Tok != TOK_EOF) { + Macro* M; SymEntry* Sym; ExprNode* EnumExpr; @@ -93,6 +95,12 @@ void DoEnum (void) continue; } + /* We have an identifier. Is it a macro? */ + if ((M = FindMacro (&CurTok.SVal)) != 0) { + MacExpandStart (M); + continue; + } + /* We have an identifier, generate a symbol */ Sym = SymFind (CurrentScope, &CurTok.SVal, SYM_ALLOC_NEW); diff --git a/src/ca65/macro.h b/src/ca65/macro.h index c2c6b5c8d..490747810 100644 --- a/src/ca65/macro.h +++ b/src/ca65/macro.h @@ -62,7 +62,7 @@ struct StrBuf; struct Macro; typedef struct Macro Macro; - + /*****************************************************************************/ /* Code */ @@ -73,7 +73,7 @@ typedef struct Macro Macro; void MacDef (unsigned Style); /* Parse a macro definition */ -void MacUndef (const StrBuf* Name, unsigned char Style); +void MacUndef (const struct StrBuf* Name, unsigned char Style); /* Undefine the macro with the given name and style. A style mismatch is * treated as if the macro didn't exist. */ @@ -84,12 +84,12 @@ void MacExpandStart (Macro* M); void MacAbort (void); /* Abort the current macro expansion */ -Macro* FindMacro (const StrBuf* Name); +Macro* FindMacro (const struct StrBuf* Name); /* Try to find the macro with the given name and return it. If no macro with * this name was found, return NULL. */ -Macro* FindDefine (const StrBuf* Name); +Macro* FindDefine (const struct StrBuf* Name); /* Try to find the define style macro with the given name and return it. If no * such macro was found, return NULL. */ diff --git a/src/ca65/struct.c b/src/ca65/struct.c index 2b27912f1..6e854727c 100644 --- a/src/ca65/struct.c +++ b/src/ca65/struct.c @@ -40,6 +40,7 @@ #include "condasm.h" #include "error.h" #include "expr.h" +#include "macro.h" #include "nexttok.h" #include "scanner.h" #include "sizeof.h" @@ -133,6 +134,16 @@ static long DoStructInternal (long Offs, unsigned Type) /* The format is "[identifier] storage-allocator [, multiplicator]" */ Sym = 0; if (CurTok.Tok == TOK_IDENT) { + + /* Beware: An identifier may also be a macro, in which case we have + * to start over. + */ + Macro* M = FindMacro (&CurTok.SVal); + if (M) { + MacExpandStart (M); + continue; + } + /* We have an identifier, generate a symbol */ Sym = SymFind (CurrentScope, &CurTok.SVal, SYM_ALLOC_NEW); -- 2.39.5