⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 infer.cxx

📁 ecos实时嵌入式操作系统
💻 CXX
📖 第 1 页 / 共 5 页
字号:
      case CdlExprOp_LogicalNot :          result = infer_handle_logical_NOT_bool(transaction, expr, subexpr.lhs_index, goal, level);          break;                case CdlExprOp_And :          result = infer_handle_AND_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, goal, level);          break;                case CdlExprOp_Or :          result = infer_handle_OR_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, goal, level);          break;      case CdlExprOp_Implies :          result = infer_handle_IMPLIES_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, goal, level);          break;              case CdlExprOp_Xor :          result = infer_handle_XOR_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, goal, level);          break;              case CdlExprOp_Eqv :          result = infer_handle_EQV_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, goal, level);          break;              case CdlExprOp_Equal :          result = infer_handle_equal_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, goal, level);          break;      case CdlExprOp_NotEqual :          result = infer_handle_equal_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, !goal, level);          break;          // <= is satisfied by a numerical equality. However the inverse relation > cannot be handled that way          // The other comparison operators are much the same.      case CdlExprOp_LessEqual :      case CdlExprOp_GreaterEqual :          if (goal) {              result = infer_handle_numerical_equal_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, true, level);          }          break;      case CdlExprOp_LessThan :      case CdlExprOp_GreaterThan :          if (!goal) {              result = infer_handle_numerical_equal_bool(transaction, expr, subexpr.lhs_index, subexpr.rhs_index, true, level);          }          break;                case CdlExprOp_Function :          result = CdlFunction::infer_bool(transaction, expr, index, goal, level);          break;                    default:          // No other inferences are implemented at this stage.          break;    }    CYG_REPORT_RETVAL(result);    return result;}//}}}//{{{  CdlInfer::subexpr_value()                boolCdlInfer::subexpr_value(CdlTransaction transaction, CdlExpression expr, unsigned int index, CdlSimpleValue& goal, int level){    CYG_REPORT_FUNCNAMETYPE("CdlInfer::subexpr_value", "result %d");    CYG_REPORT_FUNCARG4XV(transaction, expr, index, level);    CYG_PRECONDITION_CLASSC(transaction);    CYG_PRECONDITION_CLASSC(expr);    CYG_PRECONDITIONC((0 <= index) && (index < expr->sub_expressions.size()));        bool result = false;    CdlSubexpression& subexpr = expr->sub_expressions[index];    switch(subexpr.op) {              case CdlExprOp_Reference          :          // The most common case. Follow the reference, and call the appropriate function.          // Note that the reference may be unbound.          {              CdlNode node = expr->references[subexpr.reference_index].get_destination();              CdlValuable valuable = 0;              if (0 != node) {                  valuable = dynamic_cast<CdlValuable>(node);              }              result = infer_handle_reference_value(transaction, valuable, goal, level);              break;          }                case CdlExprOp_StringConstant     :          result = infer_handle_string_constant_value(subexpr.constants, goal);          break;                                                      case CdlExprOp_IntegerConstant    :          result = infer_handle_integer_constant_value(subexpr.constants, goal);          break;                case CdlExprOp_DoubleConstant     :          result = infer_handle_double_constant_value(subexpr.constants, goal);          break;      case CdlExprOp_LogicalNot         :      case CdlExprOp_And                :      case CdlExprOp_Or                 :      case CdlExprOp_Implies            :      case CdlExprOp_Xor                :      case CdlExprOp_Eqv                :      {          bool  new_goal = true;          if (("0" == goal.get_value()) || ("" == goal.get_value())) {              new_goal = false;          }          result = CdlInfer::subexpr_bool(transaction, expr, index, new_goal, level);          break;      }                case CdlExprOp_Function :          result = CdlFunction::infer_value(transaction, expr, index, goal, level);          break;              default:          // No other inferences are implemented at this stage.          break;    }    CYG_REPORT_RETVAL(result);    return result;}//}}}//}}}//{{{  Illegal value resolution                 // ----------------------------------------------------------------------------// This is not yet implemented.boolCdlConflict_IllegalValueBody::inner_resolve(CdlTransaction transaction, int level){    CYG_REPORT_FUNCNAMETYPE("CdlConflict_IllegalValue::inner_resolve", "result %d");    CYG_REPORT_FUNCARG3XV(this, transaction, level);    CYG_PRECONDITION_THISC();    CYG_PRECONDITION_CLASSC(transaction);    CYG_UNUSED_PARAM(CdlTransaction, transaction);        CYG_REPORT_RETVAL(false);    return false;}//}}}//{{{  Requires resolution                      // ----------------------------------------------------------------------------// The entry point for this code is// CdlConflict_RequiresBody::resolve(). "this" is a requires conflict// that needs to be resolved, if possible. There are twos argument: a// sub-transaction, which should be filled in with the solution if// possible; and a recursion level indicator, 0 if this is a top-level// inference engine invocation rather than a recursive one. There are// additional static parameters inference_recursion_limit and// inference_override which control details of the inference process.//// As an example of what is involved in an inference, consider the// simple case of a "requires XXX" property. This constraint may not// be satisfied because XXX is disabled,  because XXX is inactive,// or both.//// Assume for simplicity that XXX is already active. The inference// engine can now figure out that XXX must be enabled (it must be// of type bool or booldata, or else the conflict would not have// arisen). This is achieved by creating a sub-transaction,// enabling XXX in that sub-transaction, propagating the// sub-transaction and performing further inference. The inference// is successfull if no new conflicts are introduced.//// However, even if a solution is found it is not necessarily// acceptable without user confirmation, subject to// inference_override. This is handled in part by the transaction// class itself, in the resolve() and user_confirmation_required()// members. In cases where the inference engine can choose between// several alternatives it needs to consider this issue for each one.// Resolving a requires conflict. There are three ways of tackling// this problem, in order of preference://// 1) change the terms in the expression to make it evaluate to//    true.// 2) disable the source so that the requires property is no longer//    relevant.// 3) make the source inactive, with the same effect.//// The first one should always be tried. If it is entirely successful// then there is no point in looking any further. If user confirmation// is required then the second approach should be tried. If that is// entirely successful then there is no point in looking further.// If user confirmation is required then the third approach should// be tried.boolCdlConflict_RequiresBody::inner_resolve(CdlTransaction transaction, int level){    CYG_REPORT_FUNCNAME("CdlConflict_Requires::inner_resolve");    CYG_REPORT_FUNCARG3XV(this, transaction, level);    CYG_PRECONDITION_THISC();    CYG_PRECONDITION_CLASSC(transaction);    bool result = false;    CdlProperty_GoalExpression  gexpr   = dynamic_cast<CdlProperty_GoalExpression>(this->get_property());    CdlExpression               expr    = gexpr->get_expression();        // Only create the sub-transactions when needed.    CdlTransaction expr_transaction     = 0;    CdlTransaction disable_transaction  = 0;    CdlTransaction inactive_transaction = 0;    // Keep track of the preferred solution found to date.    CdlTransaction preferred_transaction = 0;    expr_transaction = transaction->make(this);    if (!CdlInfer::subexpr_bool(expr_transaction, expr, expr->first_subexpression, true, level)) {        // No luck here.        expr_transaction->cancel();        delete expr_transaction;        expr_transaction = 0;    } else {        // We have a possible solution. How acceptable is it?        if (!expr_transaction->user_confirmation_required()) {            // Whoopee.            expr_transaction->commit();            delete expr_transaction;            result = true;            CYG_REPORT_RETVAL(result);            return result;        } else {            // Maybe we can do better.            preferred_transaction = expr_transaction;            expr_transaction = 0;        }    }    // Disabling the source only makes sense if we have a bool or booldata item.    CdlValuable valuable = dynamic_cast<CdlValuable>(this->get_node());    CYG_ASSERT_CLASSC(valuable);    if ((CdlValueFlavor_Bool == valuable->get_flavor()) || (CdlValueFlavor_BoolData == valuable->get_flavor())) {        disable_transaction = transaction->make(this);        if (!CdlInfer::set_valuable_bool(disable_transaction, valuable, false, level)) {            // No luck here either.            disable_transaction->cancel();            delete disable_transaction;            disable_transaction = 0;        } else {            if (!disable_transaction->user_confirmation_required()) {                disable_transaction->commit();                delete disable_transaction;                if (0 != preferred_transaction) {                    preferred_transaction->cancel();                    delete preferred_transaction;                    preferred_transaction = 0;                }                result = true;                CYG_REPORT_RETVAL(result);                return result;            } else if (0 == preferred_transaction) {                preferred_transaction = disable_transaction;            } else if (!preferred_transaction->is_preferable_to(disable_transaction)) {                preferred_transaction->cancel();                 delete preferred_transaction;                preferred_transaction = disable_transaction;                disable_transaction = 0;            } else {                disable_transaction->cancel();                delete disable_transaction;                disable_transaction = 0;            }        }    }    // Now try for the inactive approach. This may work in cases where the disable    // approach does not if e.g. there are dependencies between two nodes in the    // same container, or if the source of the conflict is not boolean.    inactive_transaction = transaction->make(this);    if (!CdlInfer::make_inactive(inactive_transaction, valuable, level)) {        inactive_transaction->cancel();        delete inactive_transaction;        inactive_transaction = 0;    } else {        if (!inactive_transaction->user_confirmation_required()) {            inactive_transaction->commit();            delete inactive_transaction;            if (0 != preferred_transaction) {                preferred_transaction->cancel();                delete preferred_transaction;                preferred_transaction = 0;            }            result = true;            CYG_REPORT_RETVAL(result);            return result;        } else if (0 == preferred_transaction) {            preferred_transaction = inactive_transaction;        } else if (!preferred_transaction->is_preferable_to(inactive_transaction)) {            preferred_transaction->cancel();             delete preferred_transaction;            preferred_transaction = inactive_transaction;            inactive_transaction = 0;        } else {            inactive_transaction->cancel();            delete inactive_transaction;            inactive_transaction = 0;        }    }    // Is there any solution at all? If so then use the currently-preferred one.    if (0 != preferred_transaction) {        preferred_transaction->commit();        delete preferred_transaction;        preferred_transaction = 0;        result = true;    }        CYG_REPORT_RETVAL(result);    return result;}//}}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -