void AssignmentExpression::onParseRecur(AnalysisResultConstPtr ar,
                                        ClassScopePtr scope) {
  // This is that much we can do during parse phase.
  TypePtr type;
  if (m_value->is(Expression::KindOfScalarExpression)) {
    type = static_pointer_cast<ScalarExpression>(m_value)->inferenceImpl(
      ar, Type::Some, false);
  } else if (m_value->is(Expression::KindOfUnaryOpExpression)) {
    UnaryOpExpressionPtr uexp =
      dynamic_pointer_cast<UnaryOpExpression>(m_value);
    if (uexp->getOp() == T_ARRAY) {
      type = Type::Array;
    }
  }
  if (!type) type = Type::Some;

  if (m_variable->is(Expression::KindOfConstantExpression)) {
    // ...as in ClassConstant statement
    // We are handling this one here, not in ClassConstant, purely because
    // we need "value" to store in constant table.
    ConstantExpressionPtr exp =
      dynamic_pointer_cast<ConstantExpression>(m_variable);
    scope->getConstants()->add(exp->getName(), type, m_value, ar, m_variable);
  } else if (m_variable->is(Expression::KindOfSimpleVariable)) {
    SimpleVariablePtr var = dynamic_pointer_cast<SimpleVariable>(m_variable);
    scope->getVariables()->add(var->getName(), type, true, ar,
                               shared_from_this(), scope->getModifiers());
    var->clearContext(Declaration); // to avoid wrong CodeError
  } else {
    ASSERT(false); // parse phase shouldn't handle anything else
  }
}
Exemplo n.º 2
0
void AssignmentExpression::onParseRecur(AnalysisResultConstPtr ar,
                                        FileScopeRawPtr fs,
                                        ClassScopePtr scope) {
    auto isArray = false;
    if (m_value->is(Expression::KindOfUnaryOpExpression)) {
        auto uexp = dynamic_pointer_cast<UnaryOpExpression>(m_value);
        if (uexp->getOp() == T_ARRAY) {
            isArray = true;
        }
    }

    if (m_variable->is(Expression::KindOfConstantExpression)) {
        // ...as in ClassConstant statement
        // We are handling this one here, not in ClassConstant, purely because
        // we need "value" to store in constant table.
        if (isArray) {
            parseTimeFatal(fs,
                           Compiler::NoError,
                           "Arrays are not allowed in class constants");
        }
        auto exp = dynamic_pointer_cast<ConstantExpression>(m_variable);
        scope->getConstants()->add(exp->getName(), m_value, ar, m_variable);
    } else if (m_variable->is(Expression::KindOfSimpleVariable)) {
        auto var = dynamic_pointer_cast<SimpleVariable>(m_variable);
        scope->getVariables()->add(var->getName(), true, ar,
                                   shared_from_this(), scope->getModifiers());
        var->clearContext(Declaration); // to avoid wrong CodeError
    } else {
        assert(false); // parse phase shouldn't handle anything else
    }
}