Example #1
0
void DeprecatedChecker::__Svd::preCheckNode(const ast::Exp & e, SLintContext & context, SLintResult & result)
{
    const ast::CallExp & ce = static_cast<const ast::CallExp &>(e);
    const ast::exps_t args = ce.getArgs();
    if (args.size() == 2)
    {
        const ast::Exp & second = *args.back();
        if (second.isDoubleExp() && static_cast<const ast::DoubleExp &>(second).getValue() == 0)
        {
            result.report(context, e.getLocation(), *this, _("svd(..., 0) is deprecated."));
        }
    }
}
bool IconvertAnalyzer::analyze(AnalysisVisitor & visitor, const unsigned int lhs, ast::CallExp & e)
{
    if (lhs != 1)
    {
        return false;
    }

    const ast::exps_t args = e.getArgs();
    if (args.size() != 2)
    {
        return false;
    }

    ast::Exp * first = args.front();
    ast::Exp * second = args.back();

    first->accept(visitor);
    Result R1 = visitor.getResult();
    TIType & type1 = R1.getType();
    if (!type1.ismatrix())
    {
        return false;
    }
    second->accept(visitor);
    Result & R2 = visitor.getResult();

    double val;
    unsigned char ival;

    if (R2.getConstant().getDblValue(val) && tools::asInteger<unsigned char>(val, ival))
    {
        TIType::Type type;

        switch (ival)
        {
            case 0:
                type = TIType::DOUBLE;
                break;
            case 1:
                type = TIType::INT8;
                break;
            case 2:
                type = TIType::INT16;
                break;
            case 4:
                type = TIType::INT32;
                break;
            case 8:
                type = TIType::INT64;
                break;
            case 11:
                type = TIType::UINT8;
                break;
            case 12:
                type = TIType::UINT16;
                break;
            case 14:
                type = TIType::UINT32;
                break;
            case 18:
                type = TIType::UINT64;
                break;
            default:
                return false;
        }

        TIType typ(visitor.getGVN(), type, type1.rows, type1.cols);
        Result & res = e.getDecorator().setResult(typ);
        e.getDecorator().setCall(L"iconvert");
        visitor.setResult(res);
        return true;
    }

    return false;
}
bool AnalysisVisitor::analyzeIndices(TIType & type, ast::CallExp & ce)
{
    const ast::exps_t args = ce.getArgs();
    const unsigned int size = args.size();

    if (size >= 3)
    {
        // Not handle yet...
        // TODO
        return false;
    }

    if (size == 0)
    {
        Result & res = ce.getDecorator().setResult(type);
        setResult(res);
        return true;
    }

    SymbolicDimension first, second;
    bool safe, ret;

    argIndices.emplace(static_cast<ast::SimpleVar &>(ce.getName()), size, 1);
    if (size == 1)
    {
        // when there is one argument, a(?) is equivalent to A(?,1)
        // where A = matrix(a, r_a * c_a, 1)

        SymbolicDimension rows(type.rows);
        second = SymbolicDimension(getGVN(), 1);
        if (type.cols != 1)
        {
            rows *= type.cols;
        }
        ret = getDimension(rows, *args.front(), safe, first);
    }
    else
    {
        bool _safe;
        ret = getDimension(type.rows, *args.front(), _safe, first);
        if (ret)
        {
            argIndices.top().getIndex() = 2;
            ret = getDimension(type.cols, *args.back(), safe, second);
            safe = safe && _safe;
        }
        else
        {
            safe = _safe;
        }
    }
    argIndices.pop();

    if (ret)
    {
        TIType typ(getGVN(), type.type, first, second);
        Result & _res = ce.getDecorator().setResult(typ);
        setResult(_res);
        ce.getDecorator().safe = safe;
    }

    return ret;
}