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

📄 func.cxx

📁 ecos实时嵌入式操作系统
💻 CXX
📖 第 1 页 / 共 3 页
字号:
//{{{  Banner                           //============================================================================////      func.cxx////      Implementation of CDL functions////============================================================================//####COPYRIGHTBEGIN####//                                                                          // ----------------------------------------------------------------------------// Copyright (C) 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:        2001/04/20// 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>//}}}//{{{  Core                             // ----------------------------------------------------------------------------int CdlFunction::next_id        = 1;std::vector<CdlFunction*>       CdlFunction::all_functions;// Dummy initializers, for e.g. when a particular function implementation does not// support a certain type of inference.void (*CdlFunction::null_check)(CdlExpression, const CdlSubexpression&) =     (void (*)(CdlExpression, const CdlSubexpression&)) 0;bool (*CdlFunction::null_infer_bool)(CdlTransaction, CdlExpression, unsigned int, bool, int) =     (bool (*)(CdlTransaction, CdlExpression, unsigned int, bool, int)) 0;bool (*CdlFunction::null_infer_value)(CdlTransaction, CdlExpression, unsigned int, CdlSimpleValue&, int) =     (bool (*)(CdlTransaction, CdlExpression, unsigned int, CdlSimpleValue&, int)) 0;CdlFunction::CdlFunction(const char* name_arg, int number_args_arg,                         void (*check_arg)(CdlExpression, const CdlSubexpression&),                         void (*eval_arg)(CdlEvalContext&, CdlExpression, const CdlSubexpression&, CdlSimpleValue&),                         bool (*infer_bool_arg)(CdlTransaction, CdlExpression, unsigned int, bool, int),                         bool (*infer_value_arg)(CdlTransaction, CdlExpression, unsigned int, CdlSimpleValue&, int))    : name(name_arg),      number_args(number_args_arg),      check_fn(check_arg),      eval_fn(eval_arg),      infer_bool_fn(infer_bool_arg),      infer_value_fn(infer_value_arg){    id  = next_id++;    all_functions.push_back(this);}CdlFunction::~CdlFunction(){}boolCdlFunction::is_function(std::string name, int& id){    CYG_REPORT_FUNCNAMETYPE("CdlFunction::is_function", "result %d");        bool result = false;    std::vector<CdlFunction*>::const_iterator i;        for (i = all_functions.begin(); !result && (i != all_functions.end()); i++) {        if (name == (*i)->name) {            result = true;            id = (*i)->id;        }    }    CYG_REPORT_RETVAL(result);    return result;}std::stringCdlFunction::get_name(int id){    CYG_REPORT_FUNCNAME("CdlFunction::get_name");    CYG_REPORT_FUNCARG1XV(id);        std::string result  = "";    std::vector<CdlFunction*>::const_iterator i;        for (i = all_functions.begin(); i != all_functions.end(); i++) {        if (id == (*i)->id) {            result = (*i)->name;            break;        }    }    CYG_REPORT_RETURN();    return result;}intCdlFunction::get_args_count(int id){    CYG_REPORT_FUNCNAMETYPE("CdlFunction::get_args_count", "result %d");    CYG_REPORT_FUNCARG1XV(id);        int result = 0;    std::vector<CdlFunction*>::const_iterator i;        for (i = all_functions.begin(); i != all_functions.end(); i++) {        if (id == (*i)->id) {            result = (*i)->number_args;;            break;        }    }    CYG_REPORT_RETVAL(result);    return result;}voidCdlFunction::check(CdlExpression expr, const CdlSubexpression& subexpr){    CYG_REPORT_FUNCNAME("CdlFunction::check");    CYG_REPORT_FUNCARG2XV(expr, &subexpr);        int id = subexpr.func;    std::vector<CdlFunction*>::const_iterator i;        for (i = all_functions.begin(); i != all_functions.end(); i++) {        if (id == (*i)->id) {            if (CdlFunction::null_check != (*i)->check_fn) {                (*((*i)->check_fn))(expr, subexpr);            }            break;        }    }    CYG_REPORT_RETURN();}voidCdlFunction::eval(CdlEvalContext& context, CdlExpression expr, const CdlSubexpression& subexpr, CdlSimpleValue& result){    CYG_REPORT_FUNCNAME("CdlFunction::eval");    CYG_REPORT_FUNCARG4XV(&context, expr, &subexpr, &result);        int id = subexpr.func;    std::vector<CdlFunction*>::const_iterator i;        for (i = all_functions.begin(); i != all_functions.end(); i++) {        if (id == (*i)->id) {            (*((*i)->eval_fn))(context, expr, subexpr, result);            break;        }    }    CYG_REPORT_RETURN();}boolCdlFunction::infer_bool(CdlTransaction transaction, CdlExpression expr, unsigned int index, bool goal, int level){    CYG_REPORT_FUNCNAMETYPE("CdlFunction::infer_bool", "result %d");    CYG_REPORT_FUNCARG5XV(transaction, expr, index, goal, level);    bool result = false;    CdlSubexpression& subexpr = expr->sub_expressions[index];    int id = subexpr.func;    std::vector<CdlFunction*>::const_iterator i;    for (i = all_functions.begin(); i != all_functions.end(); i++) {        if (id == (*i)->id) {            if (CdlFunction::null_infer_bool != (*i)->infer_bool_fn) {                result = (*((*i)->infer_bool_fn))(transaction, expr, index, goal, level);            }            break;        }    }    CYG_REPORT_RETVAL(result);    return result;}boolCdlFunction::infer_value(CdlTransaction transaction, CdlExpression expr, unsigned int index, CdlSimpleValue& goal, int level){    CYG_REPORT_FUNCNAMETYPE("CdlFunction::infer_value", "result %d");    CYG_REPORT_FUNCARG5XV(transaction, expr, index, &goal, level);        bool result = false;    CdlSubexpression& subexpr = expr->sub_expressions[index];    int id = subexpr.func;    std::vector<CdlFunction*>::const_iterator i;    for (i = all_functions.begin(); i != all_functions.end(); i++) {        if (id == (*i)->id) {            if (CdlFunction::null_infer_value != (*i)->infer_value_fn) {                result = (*((*i)->infer_value_fn))(transaction, expr, index, goal, level);            }            break;        }    }    CYG_REPORT_RETVAL(result);    return result;}//}}}//{{{  is_substr()                      // ----------------------------------------------------------------------------// is_substr(A, B)//// For example, is_substr(CYGBLD_GLOBAL_CFLAGS, " -fno-exceptions ")//// There is one subtlety about substring matching: what to do about the// start and end of a string. If the specified substring begins with a// space then this will match either a space or the start of the string,// similarly for the final character.static std::string::size_typeis_substr_find(std::string haystack, std::string needle, std::string::size_type& len_arg){    CYG_REPORT_FUNCNAMETYPE("is_substr_find", "result %d");    std::string::size_type result       = std::string::npos;    std::string::size_type haystack_len = haystack.length();    std::string::size_type needle_len   = needle.length();    bool leading_space = false;    bool trailing_space = false;        if (' ' == needle[0]) {        leading_space = true;        needle_len--;        needle = std::string(needle, 1, needle_len);    }    if (' ' == needle[needle_len - 1]) {        trailing_space = true;        needle_len--;

⌨️ 快捷键说明

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