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

Commit 01f6d939 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

Merge commit 'goog/master' into merge_master

parents bfa833c0 192d1d79
Loading
Loading
Loading
Loading
+313 −140
Original line number Original line Diff line number Diff line
@@ -1875,9 +1875,15 @@ class Compiler : public ErrorSink {
    SymbolStack mGlobals;
    SymbolStack mGlobals;
    SymbolStack mLocals;
    SymbolStack mLocals;


    // Prebuilt types, makes things slightly faster.
    Type* mkpInt;
    Type* mkpInt;
    Type* mkpChar;
    Type* mkpChar;
    Type* mkpVoid;
    Type* mkpVoid;
    Type* mkpFloat;
    Type* mkpDouble;
    Type* mkpIntPtr;
    Type* mkpCharPtr;
    Type* mkpPtrIntFn;


    InputStream* file;
    InputStream* file;


@@ -1995,10 +2001,18 @@ class Compiler : public ErrorSink {
        }
        }
    }
    }


    VariableInfo* VI(tokenid_t t) {
    bool isSymbol(tokenid_t t) {
        if ( t < TOK_SYMBOL || ((size_t) (t-TOK_SYMBOL)) >= mTokenTable.size()) {
        return t >= TOK_SYMBOL &&
            internalError();
            ((size_t) (t-TOK_SYMBOL)) < mTokenTable.size();
    }

    bool isSymbolOrKeyword(tokenid_t t) {
        return t >= TOK_KEYWORD &&
            ((size_t) (t-TOK_KEYWORD)) < mTokenTable.size();
    }
    }

    VariableInfo* VI(tokenid_t t) {
        assert(isSymbol(t));
        VariableInfo* pV = mTokenTable[t].mpVariableInfo;
        VariableInfo* pV = mTokenTable[t].mpVariableInfo;
        if (pV && pV->tok != t) {
        if (pV && pV->tok != t) {
            internalError();
            internalError();
@@ -2010,7 +2024,8 @@ class Compiler : public ErrorSink {
        return t >= TOK_SYMBOL && VI(t) != 0;
        return t >= TOK_SYMBOL && VI(t) != 0;
    }
    }


    inline const char* nameof(tokenid_t t) {
    const char* nameof(tokenid_t t) {
        assert(isSymbolOrKeyword(t));
        return mTokenTable[t].pText;
        return mTokenTable[t].pText;
    }
    }


@@ -2324,37 +2339,48 @@ class Compiler : public ErrorSink {
        return false;
        return false;
    }
    }


    /* l is one if '=' parsing wanted (quick hack) */
    bool acceptStringLiteral() {
    void unary(intptr_t l) {
        if (tok == '"') {
        intptr_t n, t, a;
        int c;
        String tString;
        t = 0;
        n = 1; /* type of expression 0 = forward, 1 = value, other = lvalue */
        if (tok == '\"') {
            pGen->li((int) glo);
            pGen->li((int) glo);
            while (ch != '\"' && ch != EOF) {
            // This while loop merges multiple adjacent string constants.
            while (tok == '"') {
                while (ch != '"' && ch != EOF) {
                    *allocGlobalSpace(1) = getq();
                    *allocGlobalSpace(1) = getq();
                }
                }
            if (ch != '\"') {
                if (ch != '"') {
                    error("Unterminated string constant.");
                    error("Unterminated string constant.");
                }
                }
                inp();
                next();
            }
            /* Null terminate */
            *glo = 0;
            *glo = 0;
            /* align heap */
            /* align heap */
            allocGlobalSpace((char*) (((intptr_t) glo + 4) & -4) - glo);
            allocGlobalSpace((char*) (((intptr_t) glo + 4) & -4) - glo);
            inp();

            next();
            return true;
        }
        return false;
    }
    /* Parse and evaluate a unary expression.
     * allowAssignment is true if '=' parsing wanted (quick hack)
     */
    void unary(bool allowAssignment) {
        intptr_t n, t, a;
        t = 0;
        n = 1; /* type of expression 0 = forward, 1 = value, other = lvalue */
        if (acceptStringLiteral()) {
            // Nothing else to do.
        } else {
        } else {
            c = tokl;
            int c = tokl;
            a = tokc;
            a = tokc;
            t = tok;
            t = tok;
            tString = mTokenString;
            next();
            next();
            if (t == TOK_NUM) {
            if (t == TOK_NUM) {
                pGen->li(a);
                pGen->li(a);
            } else if (c == 2) {
            } else if (c == 2) {
                /* -, +, !, ~ */
                /* -, +, !, ~ */
                unary(0);
                unary(false);
                pGen->clearR1();
                pGen->clearR1();
                if (t == '!')
                if (t == '!')
                    pGen->gcmp(a);
                    pGen->gcmp(a);
@@ -2364,23 +2390,29 @@ class Compiler : public ErrorSink {
                expr();
                expr();
                skip(')');
                skip(')');
            } else if (t == '*') {
            } else if (t == '*') {
                /* parse cast */
                /* This is a pointer dereference, but we currently only
                skip('(');
                 * support a pointer dereference if it's immediately
                t = tok; /* get type */
                 * in front of a cast. So parse the cast right here.
                next(); /* skip int/char/void */
                 */
                next(); /* skip '*' or '(' */
                if (tok == '*') {
                    /* function type */
                    skip('*');
                    skip(')');
                skip('(');
                skip('(');
                    skip(')');
                Type* pCast = expectCastTypeDeclaration(mLocalArena);
                // We currently only handle 3 types of cast:
                // (int*), (char*) , (int (*)())
                if(typeEqual(pCast, mkpIntPtr)) {
                    t = TOK_INT;
                } else if (typeEqual(pCast, mkpCharPtr)) {
                    t = TOK_CHAR;
                } else if (typeEqual(pCast, mkpPtrIntFn)){
                    t = 0;
                    t = 0;
                } else {
                    String buffer;
                    decodeType(buffer, pCast);
                    error("Unsupported cast type %s", buffer.getUnwrapped());
                    decodeType(buffer, mkpPtrIntFn);
                }
                }
                skip(')');
                skip(')');
                unary(0);
                unary(false);
                if (tok == '=') {
                if (accept('=')) {
                    next();
                    pGen->pushR0();
                    pGen->pushR0();
                    expr();
                    expr();
                    pGen->popR1();
                    pGen->popR1();
@@ -2388,12 +2420,14 @@ class Compiler : public ErrorSink {
                } else if (t) {
                } else if (t) {
                    pGen->loadR0FromR0(t == TOK_INT);
                    pGen->loadR0FromR0(t == TOK_INT);
                }
                }
                // Else we fall through to the function call below, with
                // t == 0 to trigger an indirect function call. Hack!
            } else if (t == '&') {
            } else if (t == '&') {
                pGen->leaR0((int) VI(tok)->pAddress);
                pGen->leaR0((int) VI(tok)->pAddress);
                next();
                next();
            } else if (t == EOF ) {
            } else if (t == EOF ) {
                error("Unexpected EOF.");
                error("Unexpected EOF.");
            } else if (!checkSymbol(t, &tString)) {
            } else if (!checkSymbol(t)) {
                // Don't have to do anything special here, the error
                // Don't have to do anything special here, the error
                // message was printed by checkSymbol() above.
                // message was printed by checkSymbol() above.
            } else {
            } else {
@@ -2405,11 +2439,10 @@ class Compiler : public ErrorSink {
                n = (intptr_t) VI(t)->pAddress;
                n = (intptr_t) VI(t)->pAddress;
                /* forward reference: try dlsym */
                /* forward reference: try dlsym */
                if (!n) {
                if (!n) {
                    n = (intptr_t) dlsym(RTLD_DEFAULT,
                    n = (intptr_t) dlsym(RTLD_DEFAULT, nameof(t));
                                         tString.getUnwrapped());
                    VI(t)->pAddress = (void*) n;
                    VI(t)->pAddress = (void*) n;
                }
                }
                if ((tok == '=') & l) {
                if ((tok == '=') & allowAssignment) {
                    /* assignment */
                    /* assignment */
                    next();
                    next();
                    expr();
                    expr();
@@ -2417,7 +2450,7 @@ class Compiler : public ErrorSink {
                } else if (tok != '(') {
                } else if (tok != '(') {
                    /* variable */
                    /* variable */
                    if (!n) {
                    if (!n) {
                        error("Undefined variable %s", tString.getUnwrapped());
                        error("Undefined variable %s", nameof(t));
                    }
                    }
                    pGen->loadR0(n, tokl == 11, tokc);
                    pGen->loadR0(n, tokl == 11, tokc);
                    if (tokl == 11) {
                    if (tokl == 11) {
@@ -2435,13 +2468,16 @@ class Compiler : public ErrorSink {
            /* push args and invert order */
            /* push args and invert order */
            a = pGen->beginFunctionCallArguments();
            a = pGen->beginFunctionCallArguments();
            next();
            next();
            l = 0;
            int l = 0;
            while (tok != ')' && tok != EOF) {
            while (tok != ')' && tok != EOF) {
                expr();
                expr();
                pGen->storeR0ToArg(l);
                pGen->storeR0ToArg(l);
                if (tok == ',')
                    next();
                l = l + 4;
                l = l + 4;
                if (accept(',')) {
                    // fine
                } else if ( tok != ')') {
                    error("Expected ',' or ')'");
                }
            }
            }
            pGen->endFunctionCallArguments(a, l);
            pGen->endFunctionCallArguments(a, l);
            skip(')');
            skip(')');
@@ -2458,28 +2494,30 @@ class Compiler : public ErrorSink {
        }
        }
    }
    }


    void sum(int l) {
    /* Recursive descent parser for binary operations.
     */
    void binaryOp(int level) {
        intptr_t t, n, a;
        intptr_t t, n, a;
        t = 0;
        t = 0;
        if (l-- == 1)
        if (level-- == 1)
            unary(1);
            unary(true);
        else {
        else {
            sum(l);
            binaryOp(level);
            a = 0;
            a = 0;
            while (l == tokl) {
            while (level == tokl) {
                n = tok;
                n = tok;
                t = tokc;
                t = tokc;
                next();
                next();


                if (l > 8) {
                if (level > 8) {
                    a = pGen->gtst(t == OP_LOGICAL_OR, a); /* && and || output code generation */
                    a = pGen->gtst(t == OP_LOGICAL_OR, a); /* && and || output code generation */
                    sum(l);
                    binaryOp(level);
                } else {
                } else {
                    pGen->pushR0();
                    pGen->pushR0();
                    sum(l);
                    binaryOp(level);
                    pGen->popR1();
                    pGen->popR1();


                    if ((l == 4) | (l == 5)) {
                    if ((level == 4) | (level == 5)) {
                        pGen->gcmp(t);
                        pGen->gcmp(t);
                    } else {
                    } else {
                        pGen->genOp(t);
                        pGen->genOp(t);
@@ -2487,7 +2525,7 @@ class Compiler : public ErrorSink {
                }
                }
            }
            }
            /* && and || output code generation */
            /* && and || output code generation */
            if (a && l > 8) {
            if (a && level > 8) {
                a = pGen->gtst(t == OP_LOGICAL_OR, a);
                a = pGen->gtst(t == OP_LOGICAL_OR, a);
                pGen->li(t != OP_LOGICAL_OR);
                pGen->li(t != OP_LOGICAL_OR);
                pGen->gjmp(5); /* jmp $ + 5 (sizeof li, FIXME for ARM) */
                pGen->gjmp(5); /* jmp $ + 5 (sizeof li, FIXME for ARM) */
@@ -2498,7 +2536,7 @@ class Compiler : public ErrorSink {
    }
    }


    void expr() {
    void expr() {
        sum(11);
        binaryOp(11);
    }
    }


    int test_expr() {
    int test_expr() {
@@ -2509,9 +2547,10 @@ class Compiler : public ErrorSink {
    void block(intptr_t l, bool outermostFunctionBlock) {
    void block(intptr_t l, bool outermostFunctionBlock) {
        intptr_t a, n, t;
        intptr_t a, n, t;


        if (tok == TOK_INT || tok == TOK_CHAR) {
        Type* pBaseType;
        if ((pBaseType = acceptPrimitiveType(mLocalArena))) {
            /* declarations */
            /* declarations */
            localDeclarations();
            localDeclarations(pBaseType);
        } else if (tok == TOK_IF) {
        } else if (tok == TOK_IF) {
            next();
            next();
            skip('(');
            skip('(');
@@ -2567,13 +2606,11 @@ class Compiler : public ErrorSink {
                mLocals.popLevel();
                mLocals.popLevel();
            }
            }
        } else {
        } else {
            if (tok == TOK_RETURN) {
            if (accept(TOK_RETURN)) {
                next();
                if (tok != ';')
                if (tok != ';')
                    expr();
                    expr();
                rsym = pGen->gjmp(rsym); /* jmp */
                rsym = pGen->gjmp(rsym); /* jmp */
            } else if (tok == TOK_BREAK) {
            } else if (accept(TOK_BREAK)) {
                next();
                *(int *) l = pGen->gjmp(*(int *) l);
                *(int *) l = pGen->gjmp(*(int *) l);
            } else if (tok != ';')
            } else if (tok != ';')
                expr();
                expr();
@@ -2582,7 +2619,8 @@ class Compiler : public ErrorSink {
    }
    }


    enum TypeTag {
    enum TypeTag {
        TY_INT, TY_CHAR, TY_VOID, TY_POINTER, TY_FUNC, TY_PARAM
        TY_INT, TY_CHAR, TY_VOID, TY_FLOAT, TY_DOUBLE,
        TY_POINTER, TY_FUNC, TY_PARAM
    };
    };


    struct Type {
    struct Type {
@@ -2592,6 +2630,26 @@ class Compiler : public ErrorSink {
        Type* pTail;
        Type* pTail;
    };
    };


    bool typeEqual(Type* a, Type* b) {
        if (a == b) {
            return true;
        }
        if (a == NULL || b == NULL) {
            return false;
        }
        TypeTag at = a->tag;
        if (at != b->tag) {
            return false;
        }
        if (at == TY_POINTER) {
            return typeEqual(a->pHead, b->pHead);
        } else if (at == TY_FUNC || at == TY_PARAM) {
            return typeEqual(a->pHead, b->pHead)
                && typeEqual(a->pTail, b->pTail);
        }
        return true;
    }

    Type* createType(TypeTag tag, Type* pHead, Type* pTail, Arena& arena) {
    Type* createType(TypeTag tag, Type* pHead, Type* pTail, Arena& arena) {
        assert(tag >= TY_INT && tag <= TY_PARAM);
        assert(tag >= TY_INT && tag <= TY_PARAM);
        Type* pType = (Type*) arena.alloc(sizeof(Type));
        Type* pType = (Type*) arena.alloc(sizeof(Type));
@@ -2602,21 +2660,39 @@ class Compiler : public ErrorSink {
        return pType;
        return pType;
    }
    }


    Type* createPtrType(Type* pType, Arena& arena) {
        return createType(TY_POINTER, pType, NULL, arena);
    }

    /**
     * Try to print a type in declaration order
     */
    void decodeType(String& buffer, Type* pType) {
    void decodeType(String& buffer, Type* pType) {
        buffer.clear();
        if (pType == NULL) {
        if (pType == NULL) {
            buffer.appendCStr("null");
            buffer.appendCStr("null");
            return;
            return;
        }
        }
        buffer.append('(');
        decodeTypeImp(buffer, pType);
    }

    void decodeTypeImp(String& buffer, Type* pType) {
        decodeTypeImpPrefix(buffer, pType);

        String temp;
        String temp;
        if (pType->id != 0) {
        if (pType->id != 0) {
            decodeToken(temp, pType->id);
            decodeToken(temp, pType->id);
            buffer.append(temp);
            buffer.append(temp);
            buffer.append(' ');
        }
        }
        bool printHead = false;

        bool printTail = false;
        decodeTypeImpPostfix(buffer, pType);
        switch (pType->tag) {
    }

    void decodeTypeImpPrefix(String& buffer, Type* pType) {
        TypeTag tag = pType->tag;

        if (tag >= TY_INT && tag <= TY_VOID) {
            switch (tag) {
                case TY_INT:
                case TY_INT:
                    buffer.appendCStr("int");
                    buffer.appendCStr("int");
                    break;
                    break;
@@ -2626,19 +2702,41 @@ class Compiler : public ErrorSink {
                case TY_VOID:
                case TY_VOID:
                    buffer.appendCStr("void");
                    buffer.appendCStr("void");
                    break;
                    break;
                case TY_FLOAT:
                    buffer.appendCStr("float");
                    break;
                case TY_DOUBLE:
                    buffer.appendCStr("double");
                    break;
                default:
                    break;
            }
            buffer.append(' ');
        }

        switch (tag) {
            case TY_INT:
                break;
            case TY_CHAR:
                break;
            case TY_VOID:
                 break;
            case TY_FLOAT:
                 break;
            case TY_DOUBLE:
                break;
            case TY_POINTER:
            case TY_POINTER:
                buffer.appendCStr("*");
                decodeTypeImpPrefix(buffer, pType->pHead);
                printHead = true;
                if(pType->pHead && pType->pHead->tag == TY_FUNC) {
                    buffer.append('(');
                }
                buffer.append('*');
                break;
                break;
            case TY_FUNC:
            case TY_FUNC:
                buffer.appendCStr("func");
                decodeTypeImp(buffer, pType->pHead);
                printHead = true;
                printTail = true;
                break;
                break;
            case TY_PARAM:
            case TY_PARAM:
                buffer.appendCStr("param");
                decodeTypeImp(buffer, pType->pHead);
                printHead = true;
                printTail = true;
                break;
                break;
            default:
            default:
                String temp;
                String temp;
@@ -2646,15 +2744,31 @@ class Compiler : public ErrorSink {
                buffer.append(temp);
                buffer.append(temp);
                break;
                break;
        }
        }
        if (printHead) {
            buffer.append(' ');
            decodeType(buffer, pType->pHead);
    }
    }
        if (printTail) {

            buffer.append(' ');
    void decodeTypeImpPostfix(String& buffer, Type* pType) {
            decodeType(buffer, pType->pTail);
        TypeTag tag = pType->tag;

        switch(tag) {
            case TY_POINTER:
                if(pType->pHead && pType->pHead->tag == TY_FUNC) {
                    buffer.append(')');
                }
                decodeTypeImpPostfix(buffer, pType->pHead);
                break;
            case TY_FUNC:
                buffer.append('(');
                for(Type* pArg = pType->pTail; pArg; pArg = pArg->pTail) {
                    decodeTypeImp(buffer, pArg);
                    if (pArg->pTail) {
                        buffer.appendCStr(", ");
                    }
                }
                }
                buffer.append(')');
                buffer.append(')');
                break;
            default:
                break;
        }
    }
    }


    void printType(Type* pType) {
    void printType(Type* pType) {
@@ -2671,6 +2785,10 @@ class Compiler : public ErrorSink {
            pType = mkpChar;
            pType = mkpChar;
        } else if (tok == TOK_VOID) {
        } else if (tok == TOK_VOID) {
            pType = mkpVoid;
            pType = mkpVoid;
        } else if (tok == TOK_FLOAT) {
            pType = mkpFloat;
        } else if (tok == TOK_DOUBLE) {
            pType = mkpDouble;
        } else {
        } else {
            return NULL;
            return NULL;
        }
        }
@@ -2678,60 +2796,108 @@ class Compiler : public ErrorSink {
        return pType;
        return pType;
    }
    }


    Type* acceptDeclaration(const Type* pBaseType, Arena& arena) {
    Type* acceptDeclaration(Type* pType, bool nameAllowed, bool nameRequired,
        Type* pType = createType(pBaseType->tag, pBaseType->pHead,
                            Arena& arena) {
                                 pBaseType->pTail, arena);
        tokenid_t declName = 0;
        tokenid_t declName;
        pType = acceptDecl2(pType, declName, nameAllowed,
        if (pType) {
                                  nameRequired, arena);
            pType = acceptDecl2(pType, declName, arena);
        if (declName) {
            // Clone the parent type so we can set a unique ID
            pType = createType(pType->tag, pType->pHead,
                                      pType->pTail, arena);

            pType->id = declName;
            pType->id = declName;
        }
        // fprintf(stderr, "Parsed a declaration:       ");
        // fprintf(stderr, "Parsed a declaration:       ");
        // printType(pType);
        // printType(pType);
        return pType;
    }

    Type* expectDeclaration(Type* pBaseType, Arena& arena) {
        Type* pType = acceptDeclaration(pBaseType, true, true, arena);
        if (! pType) {
            error("Expected a declaration");
        }
        return pType;
    }

    /* Used for accepting types that appear in casts */
    Type* acceptCastTypeDeclaration(Arena& arena) {
        Type* pType = acceptPrimitiveType(arena);
        if (pType) {
            pType = acceptDeclaration(pType, false, false, arena);
        }
        }
        return pType;
        return pType;
    }
    }


    Type* expectDeclaration(const Type* pBaseType, Arena& arena) {
    Type* expectCastTypeDeclaration(Arena& arena) {
        Type* pType = acceptDeclaration(pBaseType, arena);
        Type* pType = acceptCastTypeDeclaration(arena);
        if (! pType) {
        if (! pType) {
            error("Expected a declaration");
            error("Expected a declaration");
        }
        }
        return pType;
        return pType;
    }
    }


    Type* acceptDecl2(Type* pType, tokenid_t& declName, Arena& arena) {
    Type* acceptDecl2(Type* pType, tokenid_t& declName,
        while (tok == '*') {
                      bool nameAllowed, bool nameRequired, Arena& arena) {
        int ptrCounter = 0;
        while (accept('*')) {
            ptrCounter++;
        }
        pType = acceptDecl3(pType, declName, nameAllowed, nameRequired, arena);
        while (ptrCounter-- > 0) {
            pType = createType(TY_POINTER, pType, NULL, arena);
            pType = createType(TY_POINTER, pType, NULL, arena);
            next();
        }
        }
        pType = acceptDecl3(pType, declName, arena);
        return pType;
        return pType;
    }
    }


    Type* acceptDecl3(Type* pType, tokenid_t& declName, Arena& arena) {
    Type* acceptDecl3(Type* pType, tokenid_t& declName,
                      bool nameAllowed, bool nameRequired, Arena& arena) {
        // direct-dcl :
        //   name
        //  (dcl)
        //   direct-dcl()
        //   direct-dcl[]
        Type* pNewHead = NULL;
        if (accept('(')) {
        if (accept('(')) {
            pType = acceptDecl2(pType, declName, arena);
            pNewHead = acceptDecl2(pNewHead, declName, nameAllowed,
                                nameRequired, arena);
            skip(')');
            skip(')');
        } else {
        } else if ((declName = acceptSymbol()) != 0) {
            declName = acceptSymbol();
            if (nameAllowed == false && declName) {
                error("Symbol %s not allowed here", nameof(declName));
            } else if (nameRequired && ! declName) {
                String temp;
                decodeToken(temp, tok);
                error("Expected symbol. Got %s", temp.getUnwrapped());
            }
        }
        }
        while (tok == '(') {
        while (accept('(')) {
            // Function declaration
            // Function declaration
            skip('(');
            Type* pTail = acceptArgs(nameAllowed, arena);
            Type* pTail = acceptArgs(arena);
            pType = createType(TY_FUNC, pType, pTail, arena);
            pType = createType(TY_FUNC, pType, pTail, arena);
            skip(')');
            skip(')');
        }
        }

        if (pNewHead) {
            Type* pA = pNewHead;
            while (pA->pHead) {
                pA = pA->pHead;
            }
            pA->pHead = pType;
            pType = pNewHead;
        }
        return pType;
        return pType;
    }
    }


    Type* acceptArgs(Arena& arena) {
    Type* acceptArgs(bool nameAllowed, Arena& arena) {
        Type* pHead = NULL;
        Type* pHead = NULL;
        Type* pTail = NULL;
        Type* pTail = NULL;
        for(;;) {
        for(;;) {
            Type* pBaseArg = acceptPrimitiveType(arena);
            Type* pBaseArg = acceptPrimitiveType(arena);
            if (pBaseArg) {
            if (pBaseArg) {
                Type* pArg = acceptDeclaration(pBaseArg, arena);
                Type* pArg = acceptDeclaration(pBaseArg, nameAllowed, false,
                                               arena);
                if (pArg) {
                if (pArg) {
                    Type* pParam = createType(TY_PARAM, pArg, NULL, arena);
                    Type* pParam = createType(TY_PARAM, pArg, NULL, arena);
                    if (!pHead) {
                    if (!pHead) {
@@ -2781,11 +2947,10 @@ class Compiler : public ErrorSink {
        mLocals.add(pDecl);
        mLocals.add(pDecl);
    }
    }


    void localDeclarations() {
    void localDeclarations(Type* pBaseType) {
        intptr_t a;
        intptr_t a;
        Type* pBaseType;


        while ((pBaseType = acceptPrimitiveType(mLocalArena)) != NULL) {
        while (pBaseType) {
            while (tok != ';' && tok != EOF) {
            while (tok != ';' && tok != EOF) {
                Type* pDecl = expectDeclaration(pBaseType, mLocalArena);
                Type* pDecl = expectDeclaration(pBaseType, mLocalArena);
                if (!pDecl) {
                if (!pDecl) {
@@ -2805,11 +2970,12 @@ class Compiler : public ErrorSink {
                    next();
                    next();
            }
            }
            skip(';');
            skip(';');
            pBaseType = acceptPrimitiveType(mLocalArena);
        }
        }
    }
    }


    bool checkSymbol() {
    bool checkSymbol() {
        return checkSymbol(tok, &mTokenString);
        return checkSymbol(tok);
    }
    }


    void decodeToken(String& buffer, tokenid_t token) {
    void decodeToken(String& buffer, tokenid_t token) {
@@ -2830,7 +2996,7 @@ class Compiler : public ErrorSink {
        }
        }
    }
    }


    bool checkSymbol(tokenid_t token, String* pText) {
    bool checkSymbol(tokenid_t token) {
        bool result = token >= TOK_SYMBOL;
        bool result = token >= TOK_SYMBOL;
        if (!result) {
        if (!result) {
            String temp;
            String temp;
@@ -2845,10 +3011,6 @@ class Compiler : public ErrorSink {
        if (tok >= TOK_SYMBOL) {
        if (tok >= TOK_SYMBOL) {
            result = tok;
            result = tok;
            next();
            next();
        } else {
            String temp;
            decodeToken(temp, tok);
            error("Expected symbol. Got %s", temp.getUnwrapped());
        }
        }
        return result;
        return result;
    }
    }
@@ -2901,6 +3063,9 @@ class Compiler : public ErrorSink {
                skip(';');
                skip(';');
            } else {
            } else {
                // Function declaration
                // Function declaration
                if (accept(';')) {
                    // forward declaration.
                } else {
                    if (name) {
                    if (name) {
                        /* patch forward references (XXX: does not work for function
                        /* patch forward references (XXX: does not work for function
                         pointers) */
                         pointers) */
@@ -2929,6 +3094,7 @@ class Compiler : public ErrorSink {
                }
                }
            }
            }
        }
        }
    }


    char* allocGlobalSpace(int bytes) {
    char* allocGlobalSpace(int bytes) {
        if (glo - pGlobalBase + bytes > ALLOC_SIZE) {
        if (glo - pGlobalBase + bytes > ALLOC_SIZE) {
@@ -3064,6 +3230,13 @@ public:
        mkpInt = createType(TY_INT, NULL, NULL, mGlobalArena);
        mkpInt = createType(TY_INT, NULL, NULL, mGlobalArena);
        mkpChar = createType(TY_CHAR, NULL, NULL, mGlobalArena);
        mkpChar = createType(TY_CHAR, NULL, NULL, mGlobalArena);
        mkpVoid = createType(TY_VOID, NULL, NULL, mGlobalArena);
        mkpVoid = createType(TY_VOID, NULL, NULL, mGlobalArena);
        mkpFloat = createType(TY_FLOAT, NULL, NULL, mGlobalArena);
        mkpDouble = createType(TY_DOUBLE, NULL, NULL, mGlobalArena);
        mkpIntPtr = createPtrType(mkpInt, mGlobalArena);
        mkpCharPtr = createPtrType(mkpChar, mGlobalArena);
        mkpPtrIntFn = createPtrType(
                  createType(TY_FUNC, mkpInt, NULL, mGlobalArena),
                  mGlobalArena);
    }
    }


    void checkForUndefinedForwardReferences() {
    void checkForUndefinedForwardReferences() {
+7 −0
Original line number Original line Diff line number Diff line
double atof(char *nptr);

int main() {
    printf("Value = %g\n", atof("10.42"));
    return 0;
}
+4 −0
Original line number Original line Diff line number Diff line
int main() {
    return printf("Hello" "," " world\n");
}
+14 −2
Original line number Original line Diff line number Diff line
@@ -59,7 +59,14 @@ def compileArm(args):
def compare(a, b):
def compare(a, b):
    if a != b:
    if a != b:
        firstDiff = firstDifference(a, b)
        firstDiff = firstDifference(a, b)
        print "Strings differ at character", firstDiff, a[firstDiff], b[firstDiff]
        print "Strings differ at character %d '%s' != '%s'" % (
            firstDiff, safeAccess(a, firstDiff), safeAccess(b, firstDiff))

def safeAccess(s, i):
    if 0 <= i < len(s):
        return s[i]
    else:
        return '?'


def firstDifference(a, b):
def firstDifference(a, b):
    commonLen = min(len(a), len(b))
    commonLen = min(len(a), len(b))
@@ -89,6 +96,11 @@ class TestACC(unittest.TestCase):
    def testRunReturnVal(self):
    def testRunReturnVal(self):
        self.compileCheck(["-R", "data/returnval-ansi.c"],
        self.compileCheck(["-R", "data/returnval-ansi.c"],
		"Executing compiled code:\nresult: 42\n")
		"Executing compiled code:\nresult: 42\n")

    def testStingLiteralConcatenation(self):
        self.compileCheck(["-R", "data/testStringConcat.c"],
		"Executing compiled code:\nresult: 13\n", "Hello, world\n")

    def testRunOTCCANSI(self):
    def testRunOTCCANSI(self):
        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")
+10 −1
Original line number Original line Diff line number Diff line
@@ -79,6 +79,11 @@ loglevel 3
    mkdir /data/misc/keystore 0770 keystore keystore
    mkdir /data/misc/keystore 0770 keystore keystore
    mkdir /data/misc/vpn 0770 system system
    mkdir /data/misc/vpn 0770 system system
    mkdir /data/misc/vpn/profiles 0770 system system
    mkdir /data/misc/vpn/profiles 0770 system system
    mkdir /data/misc/wifi 0770 wifi system
    chown wifi system /data/misc/wifi
    touch /data/misc/wifi/wpa_supplicant.conf
    chmod 0660 /data/misc/wifi/wpa_supplicant.conf
    chown wifi system /data/misc/wifi/wpa_supplicant.conf
    mkdir /data/local 0771 shell shell
    mkdir /data/local 0771 shell shell
    mkdir /data/local/tmp 0771 shell shell
    mkdir /data/local/tmp 0771 shell shell
    mkdir /data/data 0771 system system
    mkdir /data/data 0771 system system
@@ -289,13 +294,17 @@ service installd /system/bin/installd
service flash_recovery /system/bin/flash_image recovery /system/recovery.img
service flash_recovery /system/bin/flash_image recovery /system/recovery.img
    oneshot
    oneshot


service racoon /system/bin/racoon -F -f /etc/racoon/racoon.conf
service racoon /system/bin/racoon
    socket racoon stream 600 system system
    socket racoon stream 600 system system
    # racoon will setuid to vpn after getting necessary resources.
    group net_admin keystore
    disabled
    disabled
    oneshot
    oneshot


service mtpd /system/bin/mtpd
service mtpd /system/bin/mtpd
    socket mtpd stream 600 system system
    socket mtpd stream 600 system system
    user vpn
    group vpn net_admin net_raw
    disabled
    disabled
    oneshot
    oneshot


Loading