Пример #1
0
 Dimension dimension() const
 {
     EquelleType t = expr_to_norm_->type();
     if (isNumericType(t.basicType())) {
         // The norm of a Scalar or Vector has the same dimension
         // as the Scalar or Vector itself.
         return expr_to_norm_->dimension();
     } else {
         // Taking the norm of a grid entity.
         // Note: for now we always assume 3d for the
         // purpose of dimensions of these types.
         Dimension d;
         switch (t.basicType()) {
         case Vertex:
             // 0-dimensional.
             break;
         case Edge:
             d.setCoefficient(Length, 1);
             break;
         case Face:
             d.setCoefficient(Length, 2);
             break;
         case Cell:
             d.setCoefficient(Length, 3);
             break;
         default:
             throw std::logic_error("internal compiler error in NormNode::dimension().");
         }
         return d;
     }
 }
Пример #2
0
bool PgSQLType::canCastTo(PgSQLType type)
{
	// If the types are the same of belongs to the same category they naturally can be casted
	if(this->type_idx==type.type_idx ||
		(isCharacterType() && type.isCharacterType()) ||
		(isDateTimeType() && type.isDateTimeType()) ||
		(isNumericType() && type.isNumericType()) ||
		(isNetworkType() && type.isNetworkType()) ||

		//Polymorphics anyarray, anyrange, anynoarray, anyenum to anyelement
		((isPolymorphicType() && type==QString("anyelement")) ||
		 ((*this)==QString("anyelement") && type.isPolymorphicType())) ||

		//Character to network address
		((isCharacterType() || isNetworkType()) &&
		 (type.isCharacterType() || type.isNetworkType())) ||

		//Integer to OID
		((isIntegerType() || isOIDType()) &&
		 (type.isIntegerType() || type.isOIDType())) ||

		//abstime to integer
		((((*this)==QString("integer") || (*this)==QString("int4")) && type==QString("abstime")) ||
		 (((*this)==QString("abstime") && (type==QString("integer") || type==QString("int4"))))))

		return(true);

	return(false);
}
Пример #3
0
    void BytecodeVisitor::visitUnaryOpNode(UnaryOpNode *node) {
        LOG_Visitor("visitUnaryOpNode");

        node->operand()->visit(this);
        switch (node->kind()) {
            case tSUB: {
                if (!isNumericType(topOfStackType)) {
                    throw TranslationError(string("Incorrect type for SUB inside unary-node: ") + typeToName(topOfStackType), node->position());
                }
                bc()->addInsn(topOfStackType == VT_DOUBLE ? BC_DNEG : BC_INEG);
                break;
            }
            case tNOT: {
                if (topOfStackType != VT_INT && topOfStackType != VT_STRING) {
                    throw TranslationError(string("Incorrect type for NOT inside unary-node: ") + typeToName(topOfStackType), node->position());
                }
                cast(VT_INT, node, "cast in unary op node");
                bc()->addInsn(BC_ILOAD0);
                bc()->addInsn(BC_ICMP);
                break;
            }
            default:
                throw TranslationError(string("Unknown unary operation token: ") + tokenStr(node->kind()), node->position());
        }
    }
QString SqlObjGenerator::generate(const QString &dstDir)
{
    QList<QPair<QString, QString>> fieldList = tableSch->getFieldList();
    if (fieldList.isEmpty()) {
        qCritical("table not found, %s", qPrintable(tableSch->tableName()));
        return QString();
    }

    QString output;

    // Header part
    output += QString(SQLOBJECT_HEADER_TEMPLATE).arg(modelName.toUpper(), modelName);
    QListIterator<QPair<QString, QString>> it(fieldList);
    while (it.hasNext()) {
        const QPair<QString, QString> &p = it.next();
        if (isNumericType(p.second)) {
            output += QString("    %1 %2 {0};\n").arg(p.second, p.first);
        } else {
            output += QString("    %1 %2;\n").arg(p.second, p.first);
        }
    }

    // enum part
    output += QLatin1String("\n    enum PropertyIndex {\n");
    it.toFront();
    const QPair<QString, QString> &p = it.next();
    output += QString("        %1 = 0,\n").arg(fieldNameToEnumName(p.first));
    while (it.hasNext()) {
        const QPair<QString, QString> &p = it.next();
        output += QString("        %1,\n").arg(fieldNameToEnumName(p.first));
    }
    output += QLatin1String("    };\n\n");

    // primaryKeyIndex() method
    output += QLatin1String("    int primaryKeyIndex() const override { return ");
    QString pkName = tableSch->primaryKeyFieldName();
    if (pkName.isEmpty()) {
        output += QLatin1String("-1; }\n");
    } else {
        output += fieldNameToEnumName(pkName);
        output += QLatin1String("; }\n");
    }

    // auto-value field, for example auto-increment value
    output += QLatin1String("    int autoValueIndex() const override { return ");
    QString autoValue = tableSch->autoValueFieldName();
    if (autoValue.isEmpty()) {
        output += QLatin1String("-1; }\n");
    } else {
        output += fieldNameToEnumName(autoValue);
        output += QLatin1String("; }\n");
    }

    // tableName() method
    output += QLatin1String("    QString tableName() const override { return QStringLiteral(\"");
    output += tableSch->tableName();
    output += QLatin1String("\"); }\n\n");

    // Property macros part
    output += QLatin1String("private:    /*** Don't modify below this line ***/\n    Q_OBJECT\n");
    it.toFront();
    while (it.hasNext()) {
        const QPair<QString, QString> &p = it.next();
        output += QString(SQLOBJECT_PROPERTY_TEMPLATE).arg(p.second, p.first);
    }

    // Footer part
    output += QString(SQLOBJECT_FOOTER_TEMPLATE).arg(modelName.toUpper());

    // Writes to a file
    QDir dst = QDir(dstDir).filePath("sqlobjects");
    FileWriter fw(dst.filePath(modelName.toLower() + "object.h"));
    fw.write(output, false);
    return QLatin1String("sqlobjects/") + fw.fileName();
}
Пример #5
0
bool PgSQLType::acceptsPrecision(void)
{
	return(isNumericType() ||
				(!isUserType() && type_list[this->type_idx]!=QString("date") && isDateTimeType()));
}
Пример #6
0
    void BytecodeVisitor::visitBinaryOpNode(BinaryOpNode *node) {
        LOG_Visitor("visitBinaryOpNode");

        TokenKind tokenKind = node->kind();
        if (tokenKind == tAND || tokenKind == tOR) {

            node->left()->visit(this);

            bc()->addInsn(BC_ILOAD0);
            Label exitWithResult(bc());
            bc()->addBranch(node->kind() == tAND ? BC_IFICMPE : BC_IFICMPNE, exitWithResult);

            node->right()->visit(this);

            Label exit(bc());
            bc()->addBranch(BC_JA, exit);

            bc()->bind(exitWithResult);
            bc()->addInsn(node->kind() == tAND ? BC_ILOAD0 : BC_ILOAD1);

            bc()->bind(exit);
            return;
        }

        node->left()->visit(this);
        VarType leftType = topOfStackType;
        node->right()->visit(this);
        VarType rightType = topOfStackType;

        switch (tokenKind) {
            case tAOR:
            case tAAND:
            case tAXOR:
            case tMOD: {
                switch (tokenKind) {
                    case tAAND:
                        bc()->addInsn(BC_IAAND);
                        break;
                    case tAOR:
                        bc()->addInsn(BC_IAOR);
                        break;
                    case tAXOR:
                        bc()->addInsn(BC_IAXOR);
                        break;
                    case tMOD:
                        bc()->addInsn(BC_SWAP);
                        bc()->addInsn(BC_IMOD);
                        break;
                    default:;
                }
                topOfStackType = VT_INT;
                break;
            }

            case tEQ:
            case tNEQ:
            case tGT:
            case tGE:
            case tLT:
            case tLE: {
                VarType varType = equateTypes(leftType, rightType, node);
                if (!isNumericType(varType)) {
                    throw TranslationError(string("Incorrect type for COMPARE inside binary-node: ") + typeToName(varType), node->position());
                }
                if (varType == VT_DOUBLE) {
                    bc()->addInsn(BC_DCMP);
                    bc()->addInsn(BC_ILOAD0);
                }
                Label _else(bc());
                Label end(bc());
                switch (tokenKind) {
                    case tEQ:
                        bc()->addBranch(BC_IFICMPE, _else);
                        break;
                    case tNEQ:
                        bc()->addBranch(BC_IFICMPNE, _else);
                        break;
                    case tGT:
                        bc()->addBranch(BC_IFICMPG, _else);
                        break;
                    case tGE:
                        bc()->addBranch(BC_IFICMPGE, _else);
                        break;
                    case tLT:
                        bc()->addBranch(BC_IFICMPL, _else);
                        break;
                    case tLE:
                        bc()->addBranch(BC_IFICMPLE, _else);
                        break;
                    default:;
                }
                bc()->addInsn(BC_ILOAD0);
                bc()->addBranch(BC_JA, end);
                bc()->bind(_else);
                bc()->addInsn(BC_ILOAD1);
                bc()->bind(end);
                topOfStackType = VT_INT;
                break;
            }
            case tINCRSET:
            case tDECRSET:
                break;

            case tADD:
            case tSUB:
            case tMUL:
            case tDIV: {
                VarType varType = equateTypes(leftType, rightType, node);
                if (!isNumericType(varType)) {
                    throw TranslationError(string("Incorrect type for ARITHMETIC inside binary-node: ") + typeToName(varType), node->position());
                }
                switch (tokenKind) {
                    case tADD:
                        bc()->addInsn(varType == VT_DOUBLE ? BC_DADD : BC_IADD);
                        break;
                    case tSUB:
                        bc()->addInsn(BC_SWAP);
                        bc()->addInsn(varType == VT_DOUBLE ? BC_DSUB : BC_ISUB);
                        break;
                    case tMUL:
                        bc()->addInsn(varType == VT_DOUBLE ? BC_DMUL : BC_IMUL);
                        break;
                    case tDIV:
                        bc()->addInsn(BC_SWAP);
                        bc()->addInsn(varType == VT_DOUBLE ? BC_DDIV : BC_IDIV);
                        break;
                    default:
                        assert(false);
                }
                topOfStackType = varType;
                break;
            }
            default:
                throw TranslationError(string("Unknown binary operation token: ") + tokenStr(tokenKind), node->position());
        }
    }
Пример #7
0
bool PgSQLType::acceptsPrecision(void)
{
	return(isNumericType() || (type_list[this->type_idx]!="date" && isDateTimeType()));
}