Esempio n. 1
0
File: type.c Progetto: orez-/520proj
void initTypes()
{
    typeErrors = 0;
    intType = makeInt();
    boolType = makeBool();
    stringType = makeString();
    voidType = makeVoid();
}
Esempio n. 2
0
SkPath makePath() {
    SkPath path;
    for (uint32_t cIndex = 0; cIndex < fPathContourCount; ++cIndex) {
        uint32_t segments = makeSegmentCount();
        for (uint32_t sIndex = 0; sIndex < segments; ++sIndex) {
            RandomAddPath addPathType = makeAddPathType();
            ++fAddCount;
            if (fPrintName) {
                SkDebugf("%.*s%s\n", fPathDepth * 3, fTab,
                        gRandomAddPathNames[addPathType]);
            }
            switch (addPathType) {
                case kAddArc: {
                    SkRect oval = makeRect();
                    SkScalar startAngle = makeAngle();
                    SkScalar sweepAngle = makeAngle();
                    path.addArc(oval, startAngle, sweepAngle);
                    validate(path);
                    } break;
                case kAddRoundRect1: {
                    SkRect rect = makeRect();
                    SkScalar rx = makeScalar(), ry = makeScalar();
                    SkPath::Direction dir = makeDirection();
                    path.addRoundRect(rect, rx, ry, dir);
                    validate(path);
                    } break;
                case kAddRoundRect2: {
                    SkRect rect = makeRect();
                    SkScalar radii[8];
                    makeScalarArray(SK_ARRAY_COUNT(radii), radii);
                    SkPath::Direction dir = makeDirection();
                    path.addRoundRect(rect, radii, dir);
                    validate(path);
                    } break;
                case kAddRRect: {
                    SkRRect rrect = makeRRect();
                    SkPath::Direction dir = makeDirection();
                    path.addRRect(rrect, dir);
                    validate(path);
                    } break;
                case kAddPoly: {
                    SkTDArray<SkPoint> points;
                    makePointArray(&points);
                    bool close = makeBool();
                    path.addPoly(&points[0], points.count(), close);
                    validate(path);
                    } break;
                case kAddPath1:
                    if (fPathDepth < fPathDepthLimit) {
                        ++fPathDepth;
                        SkPath src = makePath();
                        validate(src);
                        SkScalar dx = makeScalar();
                        SkScalar dy = makeScalar();
                        SkPath::AddPathMode mode = makeAddPathMode();
                        path.addPath(src, dx, dy, mode);
                        --fPathDepth;
                        validate(path);
                    }
                    break;
                case kAddPath2:
                    if (fPathDepth < fPathDepthLimit) {
                        ++fPathDepth;
                        SkPath src = makePath();
                        validate(src);
                        SkPath::AddPathMode mode = makeAddPathMode();
                        path.addPath(src, mode);
                        --fPathDepth;
                        validate(path);
                    }
                    break;
                case kAddPath3:
                    if (fPathDepth < fPathDepthLimit) {
                        ++fPathDepth;
                        SkPath src = makePath();
                        validate(src);
                        SkMatrix matrix = makeMatrix();
                        SkPath::AddPathMode mode = makeAddPathMode();
                        path.addPath(src, matrix, mode);
                        --fPathDepth;
                        validate(path);
                    }
                    break;
                case kReverseAddPath:
                    if (fPathDepth < fPathDepthLimit) {
                        ++fPathDepth;
                        SkPath src = makePath();
                        validate(src);
                        path.reverseAddPath(src);
                        --fPathDepth;
                        validate(path);
                    }
                    break;
                case kMoveToPath: {
                    SkScalar x = makeScalar();
                    SkScalar y = makeScalar();
                    path.moveTo(x, y);
                    validate(path);
                    } break;
                case kRMoveToPath: {
                    SkScalar x = makeScalar();
                    SkScalar y = makeScalar();
                    path.rMoveTo(x, y);
                    validate(path);
                    } break;
                case kLineToPath: {
                    SkScalar x = makeScalar();
                    SkScalar y = makeScalar();
                    path.lineTo(x, y);
                    validate(path);
                    } break;
                case kRLineToPath: {
                    SkScalar x = makeScalar();
                    SkScalar y = makeScalar();
                    path.rLineTo(x, y);
                    validate(path);
                    } break;
                case kQuadToPath: {
                    SkPoint pt[2];
                    makePointArray(SK_ARRAY_COUNT(pt), pt);
                    path.quadTo(pt[0], pt[1]);
                    validate(path);
                    } break;
                case kRQuadToPath: {
                    SkPoint pt[2];
                    makePointArray(SK_ARRAY_COUNT(pt), pt);
                    path.rQuadTo(pt[0].fX, pt[0].fY, pt[1].fX, pt[1].fY);
                    validate(path);
                    } break;
                case kConicToPath: {
                    SkPoint pt[2];
                    makePointArray(SK_ARRAY_COUNT(pt), pt);
                    SkScalar weight = makeScalar();
                    path.conicTo(pt[0], pt[1], weight);
                    validate(path);
                    } break;
                case kRConicToPath: {
                    SkPoint pt[2];
                    makePointArray(SK_ARRAY_COUNT(pt), pt);
                    SkScalar weight = makeScalar();
                    path.rConicTo(pt[0].fX, pt[0].fY, pt[1].fX, pt[1].fY, weight);
                    validate(path);
                    } break;
                case kCubicToPath: {
                    SkPoint pt[3];
                    makePointArray(SK_ARRAY_COUNT(pt), pt);
                    path.cubicTo(pt[0], pt[1], pt[2]);
                    validate(path);
                    } break;
                case kRCubicToPath: {
                    SkPoint pt[3];
                    makePointArray(SK_ARRAY_COUNT(pt), pt);
                    path.rCubicTo(pt[0].fX, pt[0].fY, pt[1].fX, pt[1].fY, pt[2].fX, pt[2].fY);
                    validate(path);
                    } break;
                case kArcToPath: {
                    SkPoint pt[2];
                    makePointArray(SK_ARRAY_COUNT(pt), pt);
                    SkScalar radius = makeScalar();
                    path.arcTo(pt[0], pt[1], radius);
                    validate(path);
                    } break;
                case kArcTo2Path: {
                    SkRect oval = makeRect();
                    SkScalar startAngle = makeAngle();
                    SkScalar sweepAngle = makeAngle();
                    bool forceMoveTo = makeBool();
                    path.arcTo(oval, startAngle, sweepAngle, forceMoveTo);
                    validate(path);
                    } break;
                case kClosePath:
                    path.close();
                    validate(path);
                    break;
            }
        }
    }
    return path;
}
Esempio n. 3
0
File: type.c Progetto: orez-/520proj
void typeEXP(EXP* e)
{
    int counter;
    if(e == NULL) return;
    if(e->next != NULL)
        typeEXP(e->next);
    switch(e->kind)
    {
    case lvalueK:
        typeLVALUE(e->val.lvalueE);
        e->type = e->val.lvalueE->type;
        break;
    case assignK:
        typeLVALUE(e->val.assignE.lvalue);
        typeEXP(e->val.assignE.expr);
        if(compareTypes(e->val.assignE.lvalue->type, e->val.assignE.expr->type))
        {
            e->type = e->val.assignE.lvalue->type;
        }
        else
        {
            printf("%d: Type Error: Assignment of incompatible types.\n", e->lineno);
            typeErrors++;
        }
        break;
    case equalsK:
        typeEXP(e->val.equalsE.left);
        typeEXP(e->val.equalsE.right);
        if(compareTypes(e->val.equalsE.left->type, e->val.equalsE.right->type))
        {
            e->type = makeBool();
        }
        else
        {
            printf("%d: Type Error: Comparing incompatible types.\n", e->lineno);
            typeErrors++;
        }
        break;
    case notequalsK:
        typeEXP(e->val.notequalsE.left);
        typeEXP(e->val.notequalsE.right);
        if(compareTypes(e->val.notequalsE.left->type, e->val.notequalsE.right->type))
        {
            e->type = makeBool();
        }
        else
        {
            printf("%d: Type Error: Comparing incompatible types.\n", e->lineno);
            typeErrors++;
        }
        break;
    case ltK:
        typeEXP(e->val.ltE.left);
        typeEXP(e->val.ltE.right);
        if(compareTypes(e->val.ltE.left->type, e->val.ltE.right->type))
        {
            e->type = makeBool();
        }
        else
        {
            printf("%d: Type Error: Comparing incompatible types.\n", e->lineno);
            typeErrors++;
        }

        if(!compareTypes(stringType, e->val.ltE.left->type) && !compareTypes(intType, e->val.ltE.left->type))
        {
            printf("%d: Type Error: Comparisons can only be between ints or strings.\n", e->lineno);
            typeErrors++;
        }
        break;
    case gtK:
        typeEXP(e->val.gtE.left);
        typeEXP(e->val.gtE.right);
        if(compareTypes(e->val.gtE.left->type, e->val.gtE.right->type))
        {
            e->type = makeBool();
        }
        else
        {
            printf("%d: Type Error: Comparing incompatible types.\n", e->lineno);
            typeErrors++;
        }

        if(!compareTypes(stringType, e->val.gtE.left->type) && !compareTypes(intType, e->val.gtE.left->type))
        {
            printf("%d: Type Error: Comparisons can only be between ints or strings.\n", e->lineno);
            typeErrors++;
        }
        break;
    case lteK:
        typeEXP(e->val.lteE.left);
        typeEXP(e->val.lteE.right);
        if(compareTypes(e->val.lteE.left->type, e->val.lteE.right->type))
        {
            e->type = makeBool();
        }
        else
        {
            printf("%d: Type Error: Comparing incompatible types.\n", e->lineno);
            typeErrors++;
        }

        if(!compareTypes(stringType, e->val.lteE.left->type) && !compareTypes(intType, e->val.lteE.left->type))
        {
            printf("%d: Type Error: Comparisons can only be between ints or strings.\n", e->lineno);
            typeErrors++;
        }

        break;
    case gteK:
        typeEXP(e->val.gteE.left);
        typeEXP(e->val.gteE.right);
        if(compareTypes(e->val.gteE.left->type, e->val.gteE.right->type))
        {
            e->type = makeBool();
        }
        else
        {
            printf("%d: Type Error: Comparing incompatible types.\n", e->lineno);
            typeErrors++;
        }

        if(!compareTypes(stringType, e->val.gteE.left->type) && !compareTypes(intType, e->val.gteE.left->type))
        {
            printf("%d: Type Error: Comparisons can only be between ints or strings.\n", e->lineno);
            typeErrors++;
        }
        break;
    case notK:
        typeEXP(e->val.exprE);
        if(compareTypes(boolType, e->val.exprE->type))
            e->type = makeBool();
        else
        {
            printf("%d: Type Error: bool type expected.\n", e->lineno);
            typeErrors++;
        }
        break;
    case plusK:
        typeEXP(e->val.plusE.left);
        typeEXP(e->val.plusE.right);
        counter = 0;
        if(compareTypes(stringType, e->val.plusE.left->type))
            counter++;
        else if(!compareTypes(intType, e->val.plusE.left->type))
        {
            printf("%d: Type Error: incorrect types for operator '+'.\n", e->lineno);
            typeErrors++;
        }
        if(compareTypes(stringType, e->val.plusE.right->type))
            counter++;
        else if(!compareTypes(intType, e->val.plusE.right->type))
        {
            printf("%d: Type Error: incorrect types for operator '+'.\n", e->lineno);
            typeErrors++;
        }
        if(counter > 0)
            e->type = makeString();
        else
            e->type = makeInt();
        break;
    case minusK:
        typeEXP(e->val.minusE.left);
        typeEXP(e->val.minusE.right);
        if(compareTypes(e->val.minusE.left->type, e->val.minusE.right->type) && compareTypes(intType, e->val.minusE.left->type))
        {
            e->type = makeInt();
        }
        else
        {
            printf("%d: Type Error: Expected type int for subtraction.\n", e->lineno);
            typeErrors++;
        }
        break;
    case multK:
        typeEXP(e->val.multE.left);
        typeEXP(e->val.multE.right);
        if(compareTypes(e->val.multE.left->type, e->val.multE.right->type) && compareTypes(intType, e->val.multE.left->type))
        {
            e->type = makeInt();
        }
        else
        {
            printf("%d: Type Error: Expected type int for multiplication.\n", e->lineno);
            typeErrors++;
        }
        break;
    case divK:
        typeEXP(e->val.divE.left);
        typeEXP(e->val.divE.right);
        if(compareTypes(e->val.divE.left->type, e->val.divE.right->type) && compareTypes(intType, e->val.divE.left->type))
        {
            e->type = makeInt();
        }
        else
        {
            printf("%d: Type Error: Expected type int for division.\n", e->lineno);
            typeErrors++;
        }
        break;
    case modK:
        typeEXP(e->val.modE.left);
        typeEXP(e->val.modE.right);
        if(compareTypes(e->val.modE.left->type, e->val.modE.right->type) && compareTypes(intType, e->val.modE.left->type))
        {
            e->type = makeInt();
        }
        else
        {
            printf("%d: Type Error: Expected type int for mod.\n", e->lineno);
            typeErrors++;
        }
        break;
    case andK:
        typeEXP(e->val.andE.left);
        typeEXP(e->val.andE.right);
        if(compareTypes(e->val.andE.left->type, e->val.andE.right->type) && compareTypes(boolType, e->val.andE.left->type))
        {
            e->type = makeBool();
        }
        else
        {
            printf("%d: Type Error: Expected type bool for &&.\n", e->lineno);
            typeErrors++;
        }
        break;
    case orK:
        typeEXP(e->val.orE.left);
        typeEXP(e->val.orE.right);
        if(compareTypes(e->val.orE.left->type, e->val.orE.right->type) && compareTypes(boolType, e->val.orE.left->type))
        {
            e->type = makeBool();
        }
        else
        {
            printf("%d: Type Error: Expected type bool for ||.\n", e->lineno);
            typeErrors++;
        }
        break;
    case joinK:
        typeEXP(e->val.joinE.left);
        typeEXP(e->val.joinE.right);
        if(e->val.joinE.left->type->schema == NULL || e->val.joinE.right->type->schema == NULL)
        {
            return;
        }
        e->type = NEW(TYPE);
        e->type->kind = tupleidK;
        e->type->schema = joinTuples(e->val.joinE.left->type->schema, e->val.joinE.right->type->schema);
        break;
    case keepK:
        typeEXP(e->val.keepE.left);
        e->type = NEW(TYPE);
        e->type->kind = tupleidK;
        e->type->schema = keepIDs(e->val.keepE.left->type->schema, e->val.keepE.right);
        if(e->type->schema == NULL)
        {
            printf("%d: Type Error: Identifiers are not a subset of schema fields.\n", e->lineno);
            typeErrors++;
        }
        break;
    case removeK:
        typeEXP(e->val.removeE.left);
        e->type = NEW(TYPE);
        e->type->kind = tupleidK;
        e->type->schema = removeIDs(e->val.keepE.left->type->schema, e->val.keepE.right);
        if(e->type->schema == NULL)
        {
            printf("%d: Type Error: Identifiers are not a subset of schema fields.\n", e->lineno);
            typeErrors++;
        }
        break;
    case callK:
        typeARGUMENT(e->val.callE.left->symbol->val.functionS->argument, e->val.callE.right);
        e->type = e->val.callE.left->symbol->val.functionS->type;
        break;
    case tupleK:
        typeFIELDVALUE(e->val.tupleE);
        e->type = NEW(TYPE);
        e->type->kind = tupleidK;	/* SEGFAULT WARNING TODO HELP */
        e->type->schema = NEW(SCHEMA);
        makeAnonymousTuple(e->type->schema, e->val.tupleE);
        break;
    case parenK:
        typeEXP(e->val.exprE);
        e->type = e->val.exprE->type;
        break;
    case intconstK:
        e->type = makeInt();
        break;
    case trueK:
        e->type = makeBool();
        break;
    case falseK:
        e->type = makeBool();
        break;
    case stringconstK:
        e->type = makeString();
        break;
    }
}