Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 815d8b8f authored by Jack Palevich's avatar Jack Palevich
Browse files

Allow redefinition of macros.

Example:

#define A 3
#define A 4

This used to do strange things, but now works as it should.
parent 0b1827a5
Loading
Loading
Loading
Loading
+14 −8
Original line number Original line Diff line number Diff line
@@ -3292,6 +3292,7 @@ class Compiler : public ErrorSink {
    intptr_t loc; // local variable index
    intptr_t loc; // local variable index
    char* glo;  // global variable index
    char* glo;  // global variable index
    String mTokenString;
    String mTokenString;
    bool mbSuppressMacroExpansion;
    char* dptr; // Macro state: Points to macro text during macro playback.
    char* dptr; // Macro state: Points to macro text during macro playback.
    int dch;    // Macro state: Saves old value of ch during a macro playback.
    int dch;    // Macro state: Saves old value of ch during a macro playback.
    char* pGlobalBase;
    char* pGlobalBase;
@@ -3726,6 +3727,7 @@ class Compiler : public ErrorSink {
                inp();
                inp();
            }
            }
            tok = mTokenTable.intern(mTokenString.getUnwrapped(), mTokenString.len());
            tok = mTokenTable.intern(mTokenString.getUnwrapped(), mTokenString.len());
            if (! mbSuppressMacroExpansion) {
                // Is this a macro?
                // Is this a macro?
                char* pMacroDefinition = mTokenTable[tok].mpMacroDefinition;
                char* pMacroDefinition = mTokenTable[tok].mpMacroDefinition;
                if (pMacroDefinition) {
                if (pMacroDefinition) {
@@ -3735,6 +3737,7 @@ class Compiler : public ErrorSink {
                    inp();
                    inp();
                    next();
                    next();
                }
                }
            }
        } else {
        } else {
            inp();
            inp();
            if (tok == '\'') {
            if (tok == '\'') {
@@ -3809,7 +3812,9 @@ class Compiler : public ErrorSink {
    }
    }


    void doDefine() {
    void doDefine() {
        mbSuppressMacroExpansion = true;
        next();
        next();
        mbSuppressMacroExpansion = false;
        tokenid_t name = tok;
        tokenid_t name = tok;
        String* pName = new String();
        String* pName = new String();
        if (ch == '(') {
        if (ch == '(') {
@@ -4957,6 +4962,7 @@ class Compiler : public ErrorSink {
        mCompileResult = 0;
        mCompileResult = 0;
        mLineNumber = 1;
        mLineNumber = 1;
        mbBumpLine = false;
        mbBumpLine = false;
        mbSuppressMacroExpansion = false;
    }
    }


    void setArchitecture(const char* architecture) {
    void setArchitecture(const char* architecture) {
+1 −0
Original line number Original line Diff line number Diff line
// Simple tests of the C preprocessor
// Simple tests of the C preprocessor


#define A 1
#define A (4 / 2)
#define A (4 / 2)
#define B 1 // This is a comment. With a / in it.
#define B 1 // This is a comment. With a / in it.