Context::LPFindResult ContextMemory::onFindContext(const std::string& method, const Context::Params& params, const RDOParserSrcInfo& srcInfo) const { if (method == Context::METHOD_OPERATOR_DOT) { LPLocalVariable pLocalVariable = m_pLocalVariableListStack->findLocalVariable(params.identifier()); if (pLocalVariable) return rdo::Factory<FindResult>::create(SwitchContext(pLocalVariable, params)); } if (method == Context::METHOD_GET) { LPLocalVariable pLocalVariable = m_pLocalVariableListStack->findLocalVariable(params.identifier()); if (pLocalVariable) return pLocalVariable->find(Context::METHOD_GET, params, srcInfo); } if (method == Context::METHOD_SET) { LPLocalVariable pLocalVariable = m_pLocalVariableListStack->findLocalVariable(params.identifier()); if (pLocalVariable) return pLocalVariable->find(Context::METHOD_SET, params, srcInfo); } return rdo::Factory<FindResult>::create(); }
Context::FindResult ContextMemory::onFindContext(const std::string& method, const Context::Params& params, const RDOParserSrcInfo& srcInfo) const { if (method == Context::METHOD_GET) { LPLocalVariable pLocalVariable = m_pLocalVariableListStack->findLocalVariable(params.identifier()); if (pLocalVariable) return FindResult(CreateExpression(boost::bind(&contextGetLocalVariable, pLocalVariable, srcInfo))); } else if (method == Context::METHOD_SET) { LPLocalVariable pLocalVariable = m_pLocalVariableListStack->findLocalVariable(params.identifier()); if (!pLocalVariable) return FindResult(); using namespace rdo::runtime; const LPRDOCalc localVariableValue = FindResult(CreateExpression (boost::bind(&contextGetLocalVariable, pLocalVariable, srcInfo)) ).getCreateExpression()()->calc(); const LPRDOCalc rightValue = params.exists(Expression::CONTEXT_PARAM_SET_EXPRESSION) ? params.get<LPExpression>(Expression::CONTEXT_PARAM_SET_EXPRESSION)->calc() : params.get<LPRDOFUNArithm>(RDOFUNArithm::CONTEXT_PARAM_SET_ARITHM)->createCalc(pLocalVariable->getTypeInfo()); LPRDOCalc operationResult; switch (params.get<SetOperationType::Type>(Expression::CONTEXT_PARAM_SET_OPERATION_TYPE)) { case SetOperationType::NOCHANGE: RDOParser::s_parser()->error().error(srcInfo, "Недопустимый тип операции: NOCHANGE"); break; case SetOperationType::SET : operationResult = rightValue; break; case SetOperationType::ADDITION : operationResult = rdo::Factory<RDOCalcPlus>::create(localVariableValue, rightValue); break; case SetOperationType::SUBTRACTION: operationResult = rdo::Factory<RDOCalcMinus>::create(localVariableValue, rightValue); break; case SetOperationType::MULTIPLY : operationResult = rdo::Factory<RDOCalcMult>::create(localVariableValue, rightValue); break; case SetOperationType::DIVIDE : operationResult = rdo::Factory<RDOCalcDiv>::create(localVariableValue, rightValue); break; case SetOperationType::INCREMENT : operationResult = rdo::Factory<RDOCalcPlus>::create(localVariableValue, rdo::Factory<RDOCalcConst>::create(1)); break; case SetOperationType::DECRIMENT : operationResult = rdo::Factory<RDOCalcMinus>::create(localVariableValue, rdo::Factory<RDOCalcConst>::create(1)); break; } ASSERT(operationResult); return FindResult(CreateExpression(boost::bind(&contextSetLocalVariable, pLocalVariable, operationResult, srcInfo))); } return FindResult(); }