ValueType SemanticAnalyzer::typeCheck(BinaryOp& node)
{
	ValueType lhsType = node.lhs->typeCheck(*this);
	ValueType rhsType = node.rhs->typeCheck(*this);
	if(lhsType != rhsType)
	{
		std::cout << "Trying to do operation " << operatorToString(node.type) << " for operands that are type " << typeToString(lhsType) << " and " << typeToString(rhsType)  << " on line number " << node.lineNumber << "." << std::endl;
		errors = true;
		return ValueType::undefined;	// If types does not match the type is defined as undefined.
	}
	return node.lhs->typeCheck(*this);
};
Beispiel #2
0
int GroupConstraint::build(char *buffer, size_t size) const
{
	int len = 0;

	if (!m_constraints.empty())
	{
		int res1 = 0;
		int res2 = 0;
		Container::const_iterator i = m_constraints.begin();
		Container::const_iterator end = m_constraints.end();

		res1 = snprintf(buffer + len, size - len, "(");

		if (LIKELY(res1 > 0))
			len += res1;
		else
			return -1;

		res1 = (*i)->build(buffer + len, size - len);

		if (LIKELY(res1 > 0))
			len += res1;
		else
			return -1;

		for (++i; i != end; ++i)
		{
			res1 = snprintf(buffer + len, size - len, " %s ", operatorToString(m_op));

			if (LIKELY(res1 > 0))
			{
				res2 = (*i)->build(buffer + len + res1, size - len - res1);

				if (LIKELY(res2 > 0))
					len += res1 + res2;
				else
					return -1;
			}
			else
				return -1;
		}

		res1 = snprintf(buffer + len, size - len, ")");

		if (LIKELY(res1 > 0))
			len += res1;
		else
			return -1;
	}

	return len;
}
Beispiel #3
0
int SetConstraint::build(char *buffer, size_t size) const
{
    int len = snprintf(buffer, size, "(%s.%s %s (", m_field.table->name(), m_field.column->name, operatorToString(m_op));

    if (LIKELY(len > 0))
    {
        Entity::IdsList::const_iterator i = m_idsList.begin();
        Entity::IdsList::const_iterator end = m_idsList.end();
        Value value(*i);

        int res = printValue(buffer + len, size - len, m_field.column, &value);

        if (LIKELY(res > 0))
            len += res;
        else
            return -1;

        for (++i; i != end; ++i)
        {
            res = snprintf(buffer + len, size - len, ", ");

            if (LIKELY(res > 0))
                len += res;
            else
                return -1;

            value = (*i);
            res = printValue(buffer + len, size - len, m_field.column, &value);

            if (LIKELY(res > 0))
                len += res;
            else
                return -1;
        }

        res = snprintf(buffer + len, size - len, "))");

        if (LIKELY(res > 0))
            return len + res;
    }

    return -1;
}
Beispiel #4
0
int ConstConstraint::build(char *buffer, size_t size) const
{
    int len = snprintf(buffer, size, "(%s.%s %s ", m_field.table->name(), m_field.column->name, operatorToString(m_op));

    if (LIKELY(len > 0))
    {
        int res = printValue(buffer + len, size - len, m_field.column, &m_value);

        if (LIKELY(res > 0))
            len += res;
        else
            return -1;

        res = snprintf(buffer + len, size - len, ")");

        if (LIKELY(res > 0))
            return len + res;
    }

	return -1;
}
Beispiel #5
0
int FieldConstraint::build(char *buffer, size_t size) const
{
	return snprintf(buffer, size, "(%s.%s %s %s.%s)", m_fields[0].table->name(), m_fields[0].column->name, operatorToString(m_op), m_fields[1].table->name(), m_fields[1].column->name);
}