summaryrefslogtreecommitdiffstats
path: root/libacc
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-08-18 18:25:56 -0700
committerJack Palevich <jackpal@google.com>2009-08-18 18:25:56 -0700
commit815d8b8fdbd86bb2f7e5f11dc9ace9cb62212d59 (patch)
treec084d380b2aacfaccc422bf06b0c33e84d04e2d7 /libacc
parent0b1827a5b23a78da5ed88c4158c73b822b92f7a9 (diff)
downloadsystem_core-815d8b8fdbd86bb2f7e5f11dc9ace9cb62212d59.zip
system_core-815d8b8fdbd86bb2f7e5f11dc9ace9cb62212d59.tar.gz
system_core-815d8b8fdbd86bb2f7e5f11dc9ace9cb62212d59.tar.bz2
Allow redefinition of macros.
Example: #define A 3 #define A 4 This used to do strange things, but now works as it should.
Diffstat (limited to 'libacc')
-rw-r--r--libacc/acc.cpp22
-rw-r--r--libacc/tests/data/defines.c1
2 files changed, 15 insertions, 8 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index 475e308..483a1ac 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 840917d..6cb6f7e 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.