📄 infer.cxx
字号:
switch(flavor) { default : case CdlValueFlavor_None : break; case CdlValueFlavor_Bool : if (bool_goal == current_value.is_enabled()) { result = true; } else { if (valuable->is_modifiable() && (0 == dynamic_cast<CdlLoadable>(valuable)) && !transaction->changed_by_user(valuable)) { valuable->set_enabled(transaction, bool_goal, CdlValueSource_Inferred); valuable->set_source(transaction, CdlValueSource_Inferred); result = transaction->resolve_recursion(level); } } break; case CdlValueFlavor_BoolData : if (!bool_goal && !current_value.is_enabled()) { result = true; } else if (bool_goal && current_value.is_enabled() && (goal == current_value.get_simple_value())) { result = true; } else { if (valuable->is_modifiable() && (0 == dynamic_cast<CdlLoadable>(valuable)) && !transaction->changed_by_user(valuable)) { if (!bool_goal) { valuable->disable(transaction, CdlValueSource_Inferred); } else { valuable->enable_and_set_value(transaction, goal, CdlValueSource_Inferred); } valuable->set_source(transaction, CdlValueSource_Inferred); result = transaction->resolve_recursion(level); } } break; case CdlValueFlavor_Data: // Now check whether or not the valuable already has the desired value if (goal == current_value.get_simple_value()) { result = true; } else { if (valuable->is_modifiable() && (0 == dynamic_cast<CdlLoadable>(valuable)) && !transaction->changed_by_user(valuable)) { // Make the change, propagate, and perform further resolution. valuable->set_value(transaction, goal, CdlValueSource_Inferred); valuable->set_source(transaction, CdlValueSource_Inferred); result = transaction->resolve_recursion(level); } } break; } CYG_REPORT_RETVAL(result); return result;}//}}}//{{{ infer_set_valuable_bool() // ----------------------------------------------------------------------------// Deal with the boolean part of a valuable. It is assumed that active vs.// inactive is dealt with elsewhere so this code only needs to worry// about the valuable itself.static boolinfer_set_valuable_bool(CdlTransaction transaction, CdlValuable valuable, bool goal, int level){ CYG_REPORT_FUNCNAMETYPE("infer_set_valuable_bool", "result %d"); CYG_REPORT_FUNCARG4XV(transaction, valuable, goal, level); CYG_PRECONDITION_CLASSC(transaction); CYG_PRECONDITION_CLASSC(valuable); bool result = false; // Examine the current flavor. If None or Data then the valuable // is always enabled. If BoolData or Boolean then the condition // may be satisfied already, otherwise an attempt must be made // to change the value and see what happens. CdlValueFlavor flavor = valuable->get_flavor(); if (CdlValueFlavor_None == flavor) { if (goal) { result = true; } CYG_REPORT_RETVAL(result); return result; } if (CdlValueFlavor_Data == flavor) { std::string value = valuable->get_value(transaction); if (goal) { if (("" != value) && ("0" != value)) { result = true; } } else { if (("" == value) || ("0" == value)) { result = true; } } CYG_REPORT_RETVAL(result); return result; } CYG_ASSERTC((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)); bool enabled = valuable->is_enabled(transaction); if (enabled == goal) { result = true; CYG_REPORT_RETVAL(result); return result; } // enabled != goal, and we have a boolean or booldata item. // Before we actually try making any changes, is this sensible? if (!valuable->is_modifiable() || (0 != dynamic_cast<CdlLoadable>(valuable)) || transaction->changed_by_user(valuable)) { CYG_REPORT_RETVAL(result); return result; } // If we are about to disable a container, better check that this would // not annoy the user either if (!goal) { CdlContainer container = dynamic_cast<CdlContainer>(valuable); if ((0 != container) && transaction->subnode_changed_by_user(container)) { CYG_REPORT_RETVAL(result); return result; } } // Try to change the state, propagate, and perform further resolution. valuable->set_enabled(transaction, goal, CdlValueSource_Inferred); valuable->set_source(transaction, CdlValueSource_Inferred); result = transaction->resolve_recursion(level); CYG_REPORT_RETVAL(result); return result;}//}}}//{{{ infer_subexpr() //{{{ infer_handle_reference() // ----------------------------------------------------------------------------// We are processing an expression and have reached a point where we// need <reference>, !<reference> or <reference>==<value>. The// reference may currently be unbound, in which case 0 is the only// goal that can be satisfied. If the reference is bound then it may// be possible to satisfy the goal by setting the value. In addition// it is necessary to worry about active vs. inactive state.static boolinfer_handle_reference_bool(CdlTransaction transaction, CdlValuable valuable, bool goal, int level){ CYG_REPORT_FUNCNAMETYPE("infer_handle_reference_bool", "result %d"); CYG_REPORT_FUNCARG4XV(transaction, valuable, goal, level); bool result = false; if (0 == valuable) { if (!goal) { result = true; } CYG_REPORT_RETVAL(result); return result; } // If the valuable should evaluate to true then it must be both active // and be either enabled or have a non-zero value. if (goal) { if (!transaction->is_active(valuable)) { if (!infer_make_active(transaction, valuable, level)) { CYG_REPORT_RETVAL(result); return result; } } if (infer_set_valuable_bool(transaction, valuable, true, level)) { result = true; } } else { // If the valuable should evaluate to false then it must be either // inactive or it must be disabled or have a zero value. if (!transaction->is_active(valuable)) { // The goal is already satisfied, no need to proceed result = true; CYG_REPORT_RETVAL(result); return result; } // There is a choice to be made so two sub-transactions are // needed. Disabling is generally preferred to making inactive. CdlTransaction value_transaction = transaction->make(transaction->get_conflict()); CdlTransaction inactive_transaction = 0; bool value_result = infer_set_valuable_bool(value_transaction, valuable, false, level); if (value_result && !value_transaction->user_confirmation_required()) { value_transaction->commit(); delete value_transaction; value_transaction = 0; result = true; CYG_REPORT_RETVAL(result); return result; } inactive_transaction = transaction->make(transaction->get_conflict()); bool inactive_result = infer_make_inactive(inactive_transaction, valuable, level); if (!inactive_result) { if (value_result) { // Changing the value is the only solution. inactive_transaction->cancel(); value_transaction->commit(); result = true; } else { inactive_transaction->cancel(); value_transaction->cancel(); result = false; } } else { if (!value_result) { // Making the valuable inactive is the only solution. value_transaction->cancel(); inactive_transaction->commit(); result = true; } else if (!inactive_transaction->user_confirmation_required()) { // Disabling the valuable would require user confirmation, making it inactive does not value_transaction->cancel(); inactive_transaction->commit(); result = true; } else { // Both approaches are valid but would require user confirmation. // Pick the preferred one. if (value_transaction->is_preferable_to(inactive_transaction)) { inactive_transaction->cancel(); value_transaction->commit(); result = true; } else { value_transaction->cancel(); inactive_transaction->commit(); result = true; } } } delete value_transaction; delete inactive_transaction; value_transaction = 0; inactive_transaction = 0; } CYG_REPORT_RETVAL(result); return result;}// ----------------------------------------------------------------------------// Try to set a valuable to a particular value. Of course the reference// may not be bound yet.//// First check whether or not the valuable is currently active. If it is// inactive and the goal is 0 then we have succeeded. If it is active and// the goal is 0 then we could try to make the valuable inactive, but// this possibility is ignored for now in case it leads to unexpected// behaviour. If it is active then we try to set the value, using// infer_set_valuable_value().static boolinfer_handle_reference_value(CdlTransaction transaction, CdlValuable valuable, CdlSimpleValue& goal, int level){ CYG_REPORT_FUNCNAMETYPE("infer_handle_reference", "result %d"); CYG_REPORT_FUNCARG3XV(transaction, valuable, level); bool result = false; if (0 == valuable) { if (goal == (cdl_int) 0) { result = true; } } else { bool active = transaction->is_active(valuable); if (!active) { if (goal == (cdl_int) 0) { result = true; } } else { result = infer_set_valuable_value(transaction, valuable, goal, level); } } CYG_REPORT_RETVAL(result); return result;}//}}}//{{{ infer_handle_string_constant() // ----------------------------------------------------------------------------// Somewhere in the expression processing we have encountered a string// constant. The expression cannot be changed, so either the goal matches// the constant or it does not.static boolinfer_handle_string_constant_bool(CdlSimpleValue& constant, bool goal){ CYG_REPORT_FUNCNAMETYPE("infer_handle_string_constant_bool", "result %d"); bool result = false; if (goal) { if (("" != constant.get_value()) && ("0" != constant.get_value())) { result = true; } } else { if (("" == constant.get_value()) || ("0" == constant.get_value())) { result = true; } } CYG_REPORT_RETVAL(result); return result;}static boolinfer_handle_string_constant_value(CdlSimpleValue& constant, CdlSimpleValue& goal){ CYG_REPORT_FUNCNAMETYPE("infer_handle_string_constant_value", "result %d"); bool result = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -