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


C++ AST_Expression::getAsInteger方法代码示例

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


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

示例1: eval

AST_Real RangeIterator::eval(AST_Expression exp, VarSymbolTable symbolTable) {
  EvalExp evaluator(symbolTable);
  AST_Expression result =  evaluator.eval(exp);
  ERROR_UNLESS(result->expressionType() == EXPREAL || result->expressionType() == EXPINTEGER, "RangeIterator::getVal:\n"
      "Expression type should be EXPREAL or EXPINTEGER \n");
  if (result->expressionType() == EXPREAL) {
    return result->getAsReal()->val();
  } else {
    return result->getAsInteger()->val();
  }
}
开发者ID:lucciano,项目名称:modelica-cc,代码行数:11,代码来源:for_index_iterator.cpp

示例2: eval_binary_exp_exp_test

void eval_binary_exp_exp_test()
{
  AST_Expression_Integer intExp =  (AST_Expression_Integer) newAST_Expression_Integer(2);
  AST_Expression_Integer intExp2 = (AST_Expression_Integer) newAST_Expression_Integer(3);
  AST_Expression_BinOp binOp = (AST_Expression_BinOp) newAST_Expression_BinOp(intExp, intExp2, BINOPEXP);

  EvalExp *evalExp = new EvalExp(NULL);
  AST_Expression result = evalExp->eval(binOp);

  BOOST_CHECK(result->expressionType() == EXPINTEGER);
  BOOST_CHECK(result->getAsInteger()->val() == 8);
}
开发者ID:RexFuzzle,项目名称:ModelicaCC,代码行数:12,代码来源:EvalExpTest.cpp

示例3: next

AST_Real BraceIterator::next() {
  AST_Expression exp = *_braceExpElementsIter;
  AST_Real value;
  switch (exp->expressionType()){
  case EXPINTEGER:
    value = exp->getAsInteger()->val();
    break;
  case EXPREAL:
    value = (int)exp->getAsReal()->val();
    break;
  default:
    ERROR("BraceIterator::next():\n"
        "Incorrect brace expression element's type.");
  }
  _braceExpElementsIter++;
  return value;
}
开发者ID:lucciano,项目名称:modelica-cc,代码行数:17,代码来源:for_index_iterator.cpp

示例4: switch

int
MMO_EvalInitExp_::foldTraverseElement (AST_Expression exp)
{
  int ret = 0;
  switch (exp->expressionType ())
    {
    case EXPCOMPREF:
      {
	AST_Expression_ComponentReference cr = exp->getAsComponentReference ();
	VarInfo vi = _vt->lookup (cr->name ());
	if (vi == NULL)
	  {
	    Error::getInstance ()->add (exp->lineNum (),
	    EM_IR | EM_VARIABLE_NOT_FOUND,
					ER_Error, "%s", cr->name ().c_str ());
	    return (ret);
	  }
	if (!vi->isConstant ())
	  {
	    Error::getInstance ()->add (
		exp->lineNum (), EM_IR | EM_INIT_EXP, ER_Error,
		"Only constants allowed inside initial expressions. %s",
		cr->name ().c_str ());
	    return (ret);
	  }
	return (vi->value ());
      }
    case EXPBOOLEAN:
      {
	AST_Expression_Boolean eb = exp->getAsBoolean ();
	if (eb->value ())
	  {
	    return (1);
	  }
	else
	  {
	    return (0);
	  }
      }
    case EXPBOOLEANNOT:
      {
	AST_Expression_BooleanNot ebn = exp->getAsBooleanNot ();
	int res = foldTraverse (ebn->exp ());
	if (res == 0)
	  {
	    return (1);
	  }
	else
	  {
	    return (0);
	  }
      }
    case EXPREAL:
      Error::getInstance ()->add (
	  0, EM_IR | EM_INIT_EXP, ER_Warning,
	  "Implicit conversion from Real to Integer, in initial expression.");
      return (exp->getAsReal ()->val ());
    case EXPINTEGER:
      return (exp->getAsInteger ()->val ());
    default:
      Error::getInstance ()->add (
	  0,
	  EM_IR | EM_INIT_EXP,
	  ER_Warning,
	  "Initial expression not recognized, returning zero as default value.");
      break;
    }
  return (ret);
}
开发者ID:RexFuzzle,项目名称:qss-solver,代码行数:69,代码来源:expression.cpp


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