Example #1
0
// If an l-value is found, return it. Otherwise, return an r-value.
bool
SemanticAnalysis::svalue(Expression *expr, SValue *outp)
{
  // Demand only RValues.
  SaveAndSet<ValueContext> context(&value_context_, kLValue);

  LValue lval;

  // Between setting the "outparams" and returning, nothing should call us.
  assert(!outp_ && !hir_);
  outp_ = &lval;
  expr->accept(this);
  outp_ = nullptr;

  // We should not have received both an r-value and an l-value.
  assert(!hir_ || lval.kind() == LValue::Error);
  if (!hir_ && lval.kind() == LValue::Error)
    return false;

  if (hir_)
    *outp = SValue(ReturnAndVoid(hir_));
  else
    *outp = SValue(lval);
  return true;
}