From 815d8b8fdbd86bb2f7e5f11dc9ace9cb62212d59 Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Tue, 18 Aug 2009 18:25:56 -0700 Subject: [PATCH] Allow redefinition of macros. Example: #define A 3 #define A 4 This used to do strange things, but now works as it should. --- libacc/acc.cpp | 22 ++++++++++++++-------- libacc/tests/data/defines.c | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libacc/acc.cpp b/libacc/acc.cpp index 475e3087e..483a1ac62 100644 --- a/libacc/acc.cpp +++ b/libacc/acc.cpp @@ -3292,6 +3292,7 @@ class Compiler : public ErrorSink { intptr_t loc; // local variable index char* glo; // global variable index String mTokenString; + bool mbSuppressMacroExpansion; char* dptr; // Macro state: Points to macro text during macro playback. int dch; // Macro state: Saves old value of ch during a macro playback. char* pGlobalBase; @@ -3726,14 +3727,16 @@ class Compiler : public ErrorSink { inp(); } tok = mTokenTable.intern(mTokenString.getUnwrapped(), mTokenString.len()); - // Is this a macro? - char* pMacroDefinition = mTokenTable[tok].mpMacroDefinition; - if (pMacroDefinition) { - // Yes, it is a macro - dptr = pMacroDefinition; - dch = ch; - inp(); - next(); + if (! mbSuppressMacroExpansion) { + // Is this a macro? + char* pMacroDefinition = mTokenTable[tok].mpMacroDefinition; + if (pMacroDefinition) { + // Yes, it is a macro + dptr = pMacroDefinition; + dch = ch; + inp(); + next(); + } } } else { inp(); @@ -3809,7 +3812,9 @@ class Compiler : public ErrorSink { } void doDefine() { + mbSuppressMacroExpansion = true; next(); + mbSuppressMacroExpansion = false; tokenid_t name = tok; String* pName = new String(); if (ch == '(') { @@ -4957,6 +4962,7 @@ class Compiler : public ErrorSink { mCompileResult = 0; mLineNumber = 1; mbBumpLine = false; + mbSuppressMacroExpansion = false; } void setArchitecture(const char* architecture) { diff --git a/libacc/tests/data/defines.c b/libacc/tests/data/defines.c index 840917d1d..6cb6f7ebf 100644 --- a/libacc/tests/data/defines.c +++ b/libacc/tests/data/defines.c @@ -1,5 +1,6 @@ // Simple tests of the C preprocessor +#define A 1 #define A (4 / 2) #define B 1 // This is a comment. With a / in it.