コード例 #1
0
void dynamic_context::set_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc,
    store::Item_t& valueItem)
{
  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    RAISE_ERROR(err::XPDY0002, loc,
    ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varname->getStringValue()));
  }

  VarValue& var = theVarValues[varid];

  // variables can be set multiple times, so we need to make sure to remove
  // previously set temp sequences
  if (var.theState == VarValue::item)
  {
    assert(var.theValue.item != NULL);
    var.theValue.item->removeReference();
  }
  else if (var.theState == VarValue::temp_seq)
  {
    assert(var.theValue.temp_seq != NULL);
    RCHelper::removeReference(var.theValue.temp_seq);
  }
  else if (var.theState == VarValue::declared)
  {
    assert(var.theValue.item == NULL);
  }
  else
  {
    ZORBA_ASSERT(false);
  }

  var.theState = VarValue::item;
  var.theValue.item = valueItem.release();
}