当前位置: 首页>>代码示例>>C++>>正文


C++ ExprResult::getType方法代码示例

本文整理汇总了C++中ExprResult::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ ExprResult::getType方法的具体用法?C++ ExprResult::getType怎么用?C++ ExprResult::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExprResult的用法示例。


在下文中一共展示了ExprResult::getType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: eval

ExprResult CondNode::eval()
{
	ExprResult result;
	ExprResult left = mLeft->eval();
	ExprResult right = mRight->eval();
	// @TODO Realizar cast automático para string nos casos necessários
	if (left.isNumeric() && right.isNumeric())
	{
		result.setType("bool");
		if (left.isInteger())
		{
			long leftVal = left.getIntegerValue();
			if (right.isInteger())
			{
				long rightVal = right.getIntegerValue();
				result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
			}
			else
			{
				double rightVal = right.getFloatValue();
				result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
			}
		}
		else
		{
			double leftVal = left.getFloatValue();
			if (right.isInteger())
			{
				long rightVal = right.getIntegerValue();
				result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
			}
			else
			{
				double rightVal = right.getFloatValue();
				result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
			}
		}
	}
	else if (left.getType() == "string" && right.getType() == "string")
	{
		result.setType("bool");
		std::string leftVal = ((StringVal*)left.getValue())->getValue();
		std::string rightVal = ((StringVal*)right.getValue())->getValue();
		result.setValue((Val*)new BoolVal(compare(leftVal, rightVal)));
	}
	if (result.getType() == "void")
	{
		Log::fatal("Tipos incompatíveis para comparação");
	}
	return result;
}
开发者ID:emanuelzabka,项目名称:clearscript,代码行数:51,代码来源:CondNode.cpp

示例2: eval

/* @TODO Implementar melhor, copy paste de SumNode com poucas diferenças */
ExprResult ModNode::eval()
{
	ExprResult result;
	ExprResult left = mLeft->eval();
	ExprResult right = mRight->eval();
	if (left.isNumeric() && right.isNumeric())
	{
		if (left.isInteger())
		{
			long leftValue = left.getIntegerValue();
			long resultValue;
			if (right.isInteger())
			{
				long rightValue = right.getIntegerValue();
				resultValue = leftValue % rightValue;
				result.setValue("long", resultValue);
			}
			else if (right.isFloat())
			{
				long rightValue = (long)right.getFloatValue();
				resultValue = leftValue % rightValue;
				result.setValue("long", resultValue);
			}
		}
		else if (left.isFloat())
		{
			long leftValue = (long)left.getFloatValue();
			long resultValue;
			if (right.isInteger())
			{
				long rightValue = right.getIntegerValue();
				resultValue = leftValue % rightValue;
			}
			else if (right.isFloat())
			{
				long rightValue = (long)right.getFloatValue();
				resultValue = leftValue % rightValue;
			}
			result.setValue("long", resultValue);
		}
	}
	// Nenhuma operação pode ser realizada
	if (result.getType() == "void")
	{
		Log::fatal("Uso de módulo com valores não numéricos");
	}
	return result;
}
开发者ID:emanuelzabka,项目名称:clearscript,代码行数:49,代码来源:ModNode.cpp

示例3: eval

ExprResult SumNode::eval()
{
    ExprResult result;
    ExprResult left = mLeft->eval();
    ExprResult right = mRight->eval();
    if (left.isNumeric() && right.isNumeric())
    {
        if (left.isInteger())
        {
            long leftValue = left.getIntegerValue();
            if (right.isInteger())
            {
                long rightValue = right.getIntegerValue();
                long resultValue = leftValue + rightValue;
                result.setValue(result.getLargerType(left, right), resultValue);
            }
            else if (right.isFloat())
            {
                double rightValue = right.getFloatValue();
                double resultValue = leftValue + rightValue;
                result.setValue(result.getLargerType(left, right), resultValue);
            }
        }
        else if (left.isFloat())
        {
            double leftValue = left.getFloatValue();
            double resultValue = leftValue;
            if (right.isInteger())
            {
                long rightValue = right.getIntegerValue();
                resultValue += rightValue;
            }
            else if (right.isFloat())
            {
                double rightValue = right.getFloatValue();
                resultValue += rightValue;
            }
            result.setValue(result.getLargerType(left, right), resultValue);
        }
    }
    // Nenhuma operação pode ser realizada
    if (result.getType() == "void")
    {
        Log::fatal("Uso de soma com valores não numéricos");
    }
    return result;
}
开发者ID:emanuelzabka,项目名称:clearscript,代码行数:47,代码来源:SumNode.cpp


注:本文中的ExprResult::getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。