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

📄 func.cxx

📁 ecos实时嵌入式操作系统
💻 CXX
📖 第 1 页 / 共 3 页
字号:
        needle = std::string(needle, 0, needle_len);    }    std::string::size_type posn = haystack.find(needle);    while ((std::string::npos == result) && (std::string::npos != posn)) {        std::string::size_type match_point = posn;        bool match = true;        // A possible match has been found. If there was a leading        // space, check we are either at the start of the main string        // or that a space is present.        if (leading_space && (0 != posn) && (' ' != haystack[posn - 1])) {            match = false;        }        if (trailing_space && (haystack_len != (posn + needle_len)) && (' ' != haystack[posn + needle_len])) {            match = false;        }        // The result and len_arg returns exclude the spaces. This is deliberate.        // Consider !is_substr("-g -O2 -fno-rtti -fno-exceptions", " -fnortti ").        // If during inference the spaces were removed as well, this would give        // "-g -O2-fno-exceptions", which is not desirable.        if (match) {            result  = match_point;            len_arg = needle_len;        } else {            posn = haystack.find(needle, posn + 1);        }    }    CYG_REPORT_RETVAL(result);    return result;}static voidis_substr_eval(CdlEvalContext& context, CdlExpression expr, const CdlSubexpression& subexpr, CdlSimpleValue& result){    CYG_REPORT_FUNCNAME("is_substr_eval");    CYG_REPORT_FUNCARG4XV(&context, expr, &subexpr, &result);    CYG_PRECONDITION_CLASSOC(context);    CYG_PRECONDITION_CLASSC(expr);    CdlSimpleValue      arg0;    CdlSimpleValue      arg1;    expr->eval_subexpression(context, subexpr.args[0], arg0);    expr->eval_subexpression(context, subexpr.args[1], arg1);    std::string::size_type len;    result = (std::string::npos != is_substr_find(arg0.get_value(), arg1.get_value(), len));    CYG_REPORT_RETURN();}// Inference is only supported if the haystack argument is a reference that can be// updated. The needle can be an arbitrary expression.static boolis_substr_infer_bool(CdlTransaction transaction, CdlExpression expr, unsigned int index, bool goal, int level){    CYG_REPORT_FUNCNAMETYPE("is_substr_infer_bool", "result %d");    CYG_REPORT_FUNCARG5XV(transaction, expr, index, goal, level);    bool result = false;    CdlSubexpression& subexpr   = expr->sub_expressions[index];    CdlSubexpression& arg0      = expr->sub_expressions[subexpr.args[0]];    try {        if (CdlExprOp_Reference == arg0.op) {            CdlSimpleValue  needle_value;            CdlEvalContext context(transaction);            expr->eval_subexpression(context, subexpr.args[1], needle_value);            std::string     needle  = needle_value.get_value();            CdlNode         node        = expr->references[arg0.reference_index].get_destination();            CdlValuable     valuable    = 0;            if (0 != node) {                valuable = dynamic_cast<CdlValuable>(node);            }            if ((0 != valuable) && ((CdlValueFlavor_BoolData == valuable->get_flavor()) ||                                    (CdlValueFlavor_Data == valuable->get_flavor()))) {                // OK, we have a valuable which can be given a suitable value.                // What is the current string?                const CdlValue& current_value   = transaction->get_whole_value(valuable);                std::string haystack            = current_value.get_simple_value().get_value();                // What is the goal? If the needle should be in the                // haystack, append it if necessary. If the needle                // should not be in the haystack, remove all current occurrences.                if (goal) {                    std::string::size_type len;                    if (std::string::npos == is_substr_find(haystack, needle, len)) {                        haystack = haystack + needle;                    }                } else {                    std::string::size_type posn, len;                    for (posn = is_substr_find(haystack, needle, len);                         std::string::npos != posn;                         posn = is_substr_find(haystack, needle, len)) {                        haystack.erase(posn, len);                    }                }                // OK, we have a new value for the haystack which should match the desired goal.                // Try and set this value.                CdlSimpleValue  new_value(haystack);                result = CdlInfer::set_valuable_value(transaction, valuable, new_value, level);            }        }    } catch (...) {        result = false;    }        CYG_REPORT_RETVAL(result);    return result;}static CdlFunction is_substr("is_substr", 2, CdlFunction::null_check, &is_substr_eval,                             &is_substr_infer_bool, CdlFunction::null_infer_value);//}}}//{{{  is_xsubstr()                     // ----------------------------------------------------------------------------// is_xsubstr(A, B)//// Like is_substr() but only deals with exact matches, i.e. there is no special// treatment for leading and trailing spaces in the needle.static voidis_xsubstr_eval(CdlEvalContext& context, CdlExpression expr, const CdlSubexpression& subexpr, CdlSimpleValue& result){    CYG_REPORT_FUNCNAME("is_xsubstr_eval");    CYG_REPORT_FUNCARG4XV(&context, expr, &subexpr, &result);    CYG_PRECONDITION_CLASSOC(context);    CYG_PRECONDITION_CLASSC(expr);    CdlSimpleValue      arg0;    CdlSimpleValue      arg1;    expr->eval_subexpression(context, subexpr.args[0], arg0);    expr->eval_subexpression(context, subexpr.args[1], arg1);    result = (std::string::npos != arg0.get_value().find(arg1.get_value()));    CYG_REPORT_RETURN();}// Inference is only supported if the haystack argument is a reference that can be// updated. The needle can be an arbitrary expression.static boolis_xsubstr_infer_bool(CdlTransaction transaction, CdlExpression expr, unsigned int index, bool goal, int level){    CYG_REPORT_FUNCNAMETYPE("is_xsubstr_infer_bool", "result %d");    CYG_REPORT_FUNCARG5XV(transaction, expr, index, goal, level);    bool result = false;    CdlSubexpression& subexpr   = expr->sub_expressions[index];    CdlSubexpression& arg0      = expr->sub_expressions[subexpr.args[0]];    try {        if (CdlExprOp_Reference == arg0.op) {            CdlSimpleValue  needle_value;            CdlEvalContext context(transaction);            expr->eval_subexpression(context, subexpr.args[1], needle_value);            std::string     needle  = needle_value.get_value();            CdlNode         node        = expr->references[arg0.reference_index].get_destination();            CdlValuable     valuable    = 0;            if (0 != node) {                valuable = dynamic_cast<CdlValuable>(node);            }            if ((0 != valuable) && ((CdlValueFlavor_BoolData == valuable->get_flavor()) ||                                    (CdlValueFlavor_Data == valuable->get_flavor()))) {                // OK, we have a valuable which can be given a suitable value.                // What is the current string?                const CdlValue& current_value   = transaction->get_whole_value(valuable);                std::string haystack            = current_value.get_simple_value().get_value();                // What is the goal? If the needle should be in the                // haystack, append it if necessary. If the needle                // should not be in the haystack, remove all current occurrences.                if (goal) {                    if (std::string::npos == haystack.find(needle)) {                        haystack = haystack + needle;                    }                } else {                    std::string::size_type posn;                    for (posn = haystack.find(needle); std::string::npos != posn; posn = haystack.find(needle)) {                        haystack.erase(posn, needle.length());                    }                }                // OK, we have a new value for the haystack which should match the desired goal.                // Try and set this value.                CdlSimpleValue  new_value(haystack);                result = CdlInfer::set_valuable_value(transaction, valuable, new_value, level);            }        }    } catch (...) {        result = false;    }        CYG_REPORT_RETVAL(result);    return result;}static CdlFunction is_xsubstr("is_xsubstr", 2, CdlFunction::null_check, &is_xsubstr_eval,                              &is_xsubstr_infer_bool, CdlFunction::null_infer_value);//}}}//{{{  is_loaded()                      // ----------------------------------------------------------------------------// is_loaded(x)// Check whether or not a particular configuration option is loaded.// This takes a single argument which must be a reference. No// inference is possible, since loading and unloading packages is// currently beyond the scope of the inference engine.static voidis_loaded_check(CdlExpression expr, const CdlSubexpression& subexpr){    CYG_REPORT_FUNCNAME("is_loaded_check");    CYG_REPORT_FUNCARG2XV(expr, &subexpr);    CdlSubexpression& arg0 = expr->sub_expressions[subexpr.args[0]];    if (CdlExprOp_Reference != arg0.op) {        throw CdlParseException(std::string("The argument to is_loaded() should be a reference to a configuration option.\n") +                                CdlParse::get_expression_error_location());    }        CYG_REPORT_RETURN();}static voidis_loaded_eval(CdlEvalContext& context, CdlExpression expr, const CdlSubexpression& subexpr, CdlSimpleValue& result){    CYG_REPORT_FUNCNAME("is_loaded_eval");    CYG_REPORT_FUNCARG4XV(&context, expr, &subexpr, &result);    CYG_PRECONDITION_CLASSOC(context);    CYG_PRECONDITION_CLASSC(expr);    CdlSubexpression arg0 = expr->sub_expressions[subexpr.args[0]];    CYG_ASSERTC(CdlExprOp_Reference == arg0.op);    result = (0 != context.resolve_reference(expr, arg0.reference_index));    CYG_REPORT_RETURN();}static CdlFunction is_loaded("is_loaded", 1, &is_loaded_check, &is_loaded_eval,                             CdlFunction::null_infer_bool, CdlFunction::null_infer_value);//}}}//{{{  is_active()                      // ----------------------------------------------------------------------------// is_active(x)// Check whether or not a particular configuration option is loaded// and active. This takes a single argument which must be a reference.static voidis_active_check(CdlExpression expr, const CdlSubexpression& subexpr){    CYG_REPORT_FUNCNAME("is_active_check");    CYG_REPORT_FUNCARG2XV(expr, &subexpr);    CdlSubexpression& arg0 = expr->sub_expressions[subexpr.args[0]];    if (CdlExprOp_Reference != arg0.op) {        throw CdlParseException(std::string("The argument to is_active() should be a reference to a configuration option.\n") +                                CdlParse::get_expression_error_location());    }        CYG_REPORT_RETURN();}static voidis_active_eval(CdlEvalContext& context, CdlExpression expr, const CdlSubexpression& subexpr, CdlSimpleValue& result){

⌨️ 快捷键说明

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