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

📄 infer.cxx

📁 ecos实时嵌入式操作系统
💻 CXX
📖 第 1 页 / 共 5 页
字号:
//{{{  Banner                                   //============================================================================////      infer.cxx////      Inference for common conflicts.////============================================================================//####COPYRIGHTBEGIN####//                                                                          // ----------------------------------------------------------------------------// Copyright (C) 1999, 2000, 2001 Red Hat, Inc.//// This file is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.//// ----------------------------------------------------------------------------//                                                                          //####COPYRIGHTEND####//============================================================================//#####DESCRIPTIONBEGIN####//// Author(s):   bartv// Contact(s):  bartv// Date:        1999/11/1// Version:     0.01////####DESCRIPTIONEND####//============================================================================//}}}//{{{  #include's                               // ----------------------------------------------------------------------------#include "cdlconfig.h"// Get the infrastructure types, assertions, tracing and similar// facilities.#include <cyg/infra/cyg_ass.h>#include <cyg/infra/cyg_trac.h>// <cdlcore.hxx> defines everything implemented in this module.// It implicitly supplies <string>, <vector> and <map> because// the class definitions rely on these headers.#include <cdlcore.hxx>//}}}//{{{  CdlInfer class                           //{{{  Description                              // ----------------------------------------------------------------------------// The following functions provide the main entry points for inference.//// 1) bool CdlInfer::make_active(CdlTransaction, CdlValuable, level)//    Do whatever it takes to make the valuable active in//    a clean sub-transaction, if possible.// 2) bool CdlInfer::make_inactive(CdlTransaction, CdlValuable, level)//    Do whatever it takes to make the valuable inactive.// 3) bool CdlInfer::set_valuable_value(CdlTransaction, CdlValuable, CdlSimpleValue&, level)//    Try to set the valuable to the specified value, taking into//    account the different flavors.// 4) bool CdlInfer::set_valuable_bool(CdlTransaction, CdlValuable, bool, level)//    Similar to (3) but deals with the boolean aspect of the valuable//    rather than the data part.// 5) bool CdlInfer::subexpr(CdlTransaction, CdlExpression, int index, CdlSimpleValue& goal, level)//    Process a sub-expression and try to make it evaluate to the//    goal.// 6) bool CdlInfer::subexpr_bool(CdlTransaction, CdlExpression, int index, bool goal, level)//    Ditto but only deal with boolean goals. If the expression starts to//    involve arithmetic etc. then we need to move to CdlInfer::subexpr()////    As might be expected, the sub-expression handlers contain a big//    switch statement and calls into various auxiliary functions when//    necessary.//// For convenience the various entry points check whether or not the// desired condition is already satisfied.//}}}//{{{  Forward declarations                     // ----------------------------------------------------------------------------static bool infer_handle_interface_value(CdlTransaction, CdlInterface, CdlSimpleValue&, int);static bool infer_handle_reference_bool(CdlTransaction, CdlValuable, bool, int);//}}}//{{{  CdlInfer::make_active()                  // ----------------------------------------------------------------------------// Making a node active. This requires the following conditions to be// satisfied:// 1) the parent must be made active// 2) if the parent has flavor bool or booldata, it must be enabled// 3) any active_if properties boolCdlInfer::make_active(CdlTransaction transaction, CdlNode node, int level){    CYG_REPORT_FUNCNAMETYPE("CdlInfer::make_active", "result %d");    CYG_REPORT_FUNCARG3XV(transaction, node, level);    CYG_PRECONDITION_CLASSC(transaction);    CYG_PRECONDITION_CLASSC(node);    bool result = false;    if (transaction->is_active(node)) {        result = true;        CYG_REPORT_RETVAL(result);        return result;    }        CdlContainer parent = node->get_parent();    CYG_ASSERT_CLASSC(parent);    if (!transaction->is_active(parent)) {        if (!CdlInfer::make_active(transaction, parent, level)) {            CYG_REPORT_RETVAL(result);            return result;        }    }    // The parent is now active. Does it have to be enabled as well?    CdlValuable parent_valuable = dynamic_cast<CdlValuable>(static_cast<CdlNode>(parent));    if (0 != parent_valuable) {        CdlValueFlavor flavor = parent_valuable->get_flavor();        if (((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)) &&            !parent_valuable->is_enabled(transaction)) {            if (!CdlInfer::set_valuable_bool(transaction, parent_valuable, true, level)) {                CYG_REPORT_RETVAL(result);                return result;            }        }    }    // The parent is now active and enabled. Are there any active_if properties to worry about?    CdlValuable valuable = dynamic_cast<CdlValuable>(node);    if (0 != valuable) {        std::vector<CdlProperty_GoalExpression> active_if_goals;        std::vector<CdlProperty_GoalExpression>::iterator goal_i;        valuable->get_active_if_conditions(active_if_goals);        for (goal_i = active_if_goals.begin(); goal_i != active_if_goals.end(); goal_i++) {                        CdlEvalContext context(transaction, valuable, *goal_i);            try {                if (!(*goal_i)->eval(context)) {                    CdlExpression expr = (*goal_i)->get_expression();                    if (!CdlInfer::subexpr_bool(transaction, expr, expr->first_subexpression, true, level)) {                        CYG_REPORT_RETVAL(result);                        return result;                    }                }            } catch(...) {                CYG_REPORT_RETVAL(result);                return result;            }        }            }        result = transaction->is_active(node);    CYG_REPORT_RETVAL(result);    return result;}//}}}//{{{  CdlInfer::make_inactive()                // ----------------------------------------------------------------------------// Making a node inactive can be done in three ways:// 1) if the parent is boolean, try disabling it// 2) otherwise if the parent can be made inactive, that will do//    fine.// 3) if there are any active_if properties, they could be considered//    as well. For now this possibility is ignored.boolCdlInfer::make_inactive(CdlTransaction transaction, CdlNode node, int level){    CYG_REPORT_FUNCNAMETYPE("CdlInfer::make_inactive", "result %d");    CYG_REPORT_FUNCARG3XV(transaction, node, level);    CYG_PRECONDITION_CLASSC(transaction);    CYG_PRECONDITION_CLASSC(node);    bool result = false;    if (!transaction->is_active(node)) {        result = true;        CYG_REPORT_RETVAL(result);        return result;    }    CdlContainer parent = node->get_parent();    if (0 == parent) {        // No point in trying to disable the entire configuration.        CYG_REPORT_RETVAL(result);        return result;    }        CdlValuable  parent_valuable = dynamic_cast<CdlValuable>(parent);    if (0 != parent_valuable) {        CdlValueFlavor flavor = parent_valuable->get_flavor();        if ((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)) {            // Since the current node is active the parent must currently be enabled.            // A sub-transaction is needed because an alternative approach is            // possible later on.            CdlTransaction subtransaction = transaction->make(transaction->get_conflict());            if (CdlInfer::set_valuable_bool(subtransaction, parent_valuable, false, level)) {                subtransaction->commit();                delete subtransaction;                result = true;                CYG_REPORT_RETVAL(result);                return result;            } else {                subtransaction->cancel();                delete subtransaction;            }        }    }    // It is not possible to disable the parent. How about making it inactive?    if (CdlInfer::make_inactive(transaction, parent, level)) {        result = true;        CYG_REPORT_RETVAL(result);        return result;    }    // For now do not try to mess about with active_if conditions.        CYG_REPORT_RETVAL(result);    return result;}//}}}//{{{  CdlInfer::set_valuable_value()           // ----------------------------------------------------------------------------// Deal with the value part of a valuable. The valuable is known to exist// and be active, so this code only deals with the actual value part.boolCdlInfer::set_valuable_value(CdlTransaction transaction, CdlValuable valuable, CdlSimpleValue& goal, int level){    CYG_REPORT_FUNCNAMETYPE("CdlInfer::set_valuable_value", "result %d");    CYG_REPORT_FUNCARG3XV(transaction, valuable, level);    CYG_PRECONDITION_CLASSC(transaction);    CYG_PRECONDITION_CLASSC(valuable);    CYG_PRECONDITIONC(transaction->is_active(valuable));    bool result = false;    const CdlValue& current_value = transaction->get_whole_value(valuable);    CdlValueFlavor  flavor        = current_value.get_flavor();    bool bool_goal                = goal.get_bool_value();    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);              } else if (0 != dynamic_cast<CdlInterface>(valuable)) {                  // Interfaces are not directly modifiable, but their implementors are.                  result = infer_handle_interface_value(transaction, dynamic_cast<CdlInterface>(valuable), goal, 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);            } else if (0 != dynamic_cast<CdlInterface>(valuable)) {                // Interfaces are not directly modifiable, but their implementors are.                result = infer_handle_interface_value(transaction, dynamic_cast<CdlInterface>(valuable), goal, level);            }        }        break;    }

⌨️ 快捷键说明

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