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

Commit 0b2de0de authored by Jack Palevich's avatar Jack Palevich
Browse files

Allow parenthesized expressions as the value of defines

For example, this now works:

#define A (1 + 2)

Note that we still don't support defines with argument lists, so this is
still illegal:

#define A(X) (X + 2)

Also in this change: The compiler test script allows command-line
arguments to disable testing on ARM and to disable testing the output
of the old OTCC compiler.

Disabling testing on ARM is handy for developing front-end code when no
device or emulator is available.

Disabling testing OTCC output is handy for some 64-bit Linux environments,
because the original OTCC needs some tweaking to be fully compatible, and
I don't have time to investigate this problem right now.
parent 7f5b1a2b
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -3812,9 +3812,6 @@ class Compiler : public ErrorSink {
        next();
        next();
        tokenid_t name = tok;
        tokenid_t name = tok;
        String* pName = new String();
        String* pName = new String();
        while (isspace(ch)) {
            inp();
        }
        if (ch == '(') {
        if (ch == '(') {
            delete pName;
            delete pName;
            error("Defines with arguments not supported");
            error("Defines with arguments not supported");
+7 −0
Original line number Original line Diff line number Diff line
// Simple tests of the C preprocessor

#define A (1 + 2)

int main() {
    return A;
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -2,5 +2,5 @@


SCRIPT_DIR=`dirname $BASH_SOURCE`
SCRIPT_DIR=`dirname $BASH_SOURCE`
cd $SCRIPT_DIR
cd $SCRIPT_DIR
python test.py
python test.py "$@"
+45 −11
Original line number Original line Diff line number Diff line
@@ -4,9 +4,28 @@
import unittest
import unittest
import subprocess
import subprocess
import os
import os
import sets
import sys


gArmInitialized = False
gArmInitialized = False
gUseArm = True
gUseX86 = True
gRunOTCCOutput = True


def parseArgv():
    global gUseArm
    global gRunOTCCOutput
    for arg in sys.argv[1:]:
        if arg == "--noarm":
            print "--noarm detected, not testing on ARM"
            gUseArm = False
        elif arg == "--norunotcc":
            print "--norunotcc detected, not running OTCC output"
            gRunOTCCOutput = False
        else:
            print "Unknown parameter: ", arg
            raise "Unknown parameter"
    sys.argv = sys.argv[0:1]


def compile(args):
def compile(args):
    proc = subprocess.Popen(["acc"] + args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    proc = subprocess.Popen(["acc"] + args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
@@ -131,11 +150,13 @@ class TestACC(unittest.TestCase):


    def compileCheck(self, args, stdErrResult, stdOutResult="",
    def compileCheck(self, args, stdErrResult, stdOutResult="",
                     targets=['arm', 'x86']):
                     targets=['arm', 'x86']):
        targetSet = sets.ImmutableSet(targets)
        global gUseArm
        if False and 'x86' in targetSet:
        global gUseX86
        targetSet = frozenset(targets)
        if gUseX86 and 'x86' in targetSet:
            out, err = compile(args)
            out, err = compile(args)
            self.checkResult(out, err, stdErrResult, stdOutResult)
            self.checkResult(out, err, stdErrResult, stdOutResult)
        if 'arm' in targetSet:
        if gUseArm and 'arm' in targetSet:
            out = compileArm(rewritePaths(args))
            out = compileArm(rewritePaths(args))
            self.checkResult(out, "", stdErrResult, stdOutResult)
            self.checkResult(out, "", stdErrResult, stdOutResult)


@@ -157,11 +178,15 @@ class TestACC(unittest.TestCase):
        "Executing compiled code:\nresult: 13\n", "Hello, world\n")
        "Executing compiled code:\nresult: 13\n", "Hello, world\n")


    def testRunOTCCANSI(self):
    def testRunOTCCANSI(self):
        global gRunOTCCOutput
        if gRunOTCCOutput:
            self.compileCheck(["-R", "data/otcc-ansi.c", "data/returnval.c"],
            self.compileCheck(["-R", "data/otcc-ansi.c", "data/returnval.c"],
                "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\natcc-ansi.c: result: 42\nresult: 42\n", "",
                "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\natcc-ansi.c: result: 42\nresult: 42\n", "",
                 ['x86'])
                 ['x86'])


    def testRunOTCCANSI2(self):
    def testRunOTCCANSI2(self):
        global gRunOTCCOutput
        if gRunOTCCOutput:
            self.compileCheck(["-R", "data/otcc-ansi.c", "data/otcc.c", "data/returnval.c"],
            self.compileCheck(["-R", "data/otcc-ansi.c", "data/otcc.c", "data/returnval.c"],
                "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\notcc.c: about to execute compiled code.\natcc-ansi.c: result: 42\nresult: 42\n", "",['x86'])
                "Executing compiled code:\notcc-ansi.c: About to execute compiled code:\notcc.c: about to execute compiled code.\natcc-ansi.c: result: 42\nresult: 42\n", "",['x86'])


@@ -409,8 +434,17 @@ lmnopabcdefghijklmno
result: 0
result: 0
""","""""")
""","""""")


if __name__ == '__main__':
    def testDefines(self):
        self.compileCheck(["-R", "data/defines.c"], """Executing compiled code:
result: 3
""","""""")

def main():
    parseArgv()
    if not outputCanRun():
    if not outputCanRun():
        print "Many tests are expected to fail, because acc is not a 32-bit x86 Linux executable."
        print "Can't run output of acc compiler."
    unittest.main()
    unittest.main()


if __name__ == '__main__':
    main()