<commit_before>import * as Conf from './conf';
import * as GT from './types';


export function gen_api_opts(fnDef: GT.Win32FnDefMacro, fns?: GT.FnName[], settings?: GT.LoadSettings): GT.Win32FnDef {
    let opts = <GT.Win32FnDef> {};

    if (fns && Array.isArray(fns) && fns.length) {
        for (let fn of fns) {
            const ps: GT.FnParamsMacro = fnDef[fn];

            if (ps) {
                Object.defineProperty(opts, <string> fn, {
                    value: <GT.FnParams> parse_placeholder(ps, settings),
                    writable: false,
                    enumerable: true,
                    configurable: false,
                });
            }
        }
    }
    else {
        for (let fn in fnDef) {
            if ( ! {}.hasOwnProperty.call(fnDef, fn)) {
                continue;
            }
            const ps: GT.FnParamsMacro = fnDef[fn];

            if (ps) {
                Object.defineProperty(opts, <string> fn, {
                    value: <GT.FnParams> parse_placeholder(ps, settings),
                    writable: false,
                    enumerable: true,
                    configurable: false,
                });
            }
        }
    }

    return opts;
}

export function parse_placeholder(ps: GT.FnParamsMacro, settings?: GT.LoadSettings): GT.FnParams {
    const returnParam: GT.FnRetTypeMacro = ps[0];
    const callParams: GT.FnCallParamsMacro = ps[1];
    let res = <GT.FnParams> new Array(2);

    // return param
    res[0] = parse_param_placeholder(returnParam, settings);

    // callling params
    if (callParams && Array.isArray(callParams)) {  // [ [placeholder, string, string],  [placeholder, string, string], string]
        let targetParams = <GT.FnCallParams> new Array();

        for (let i = 0, len = callParams.length; i < len; i++) {
            targetParams[i] = parse_param_placeholder(returnParam, settings);
        }
        res[1] = targetParams;
    }
    else {
        throw new Error('parse_placeholder() param ps[1] invalid');
    }

    return res;
}


// convert typeof array of param to string such like ['_WIN64_HOLDER_', 'int64', 'int32'], no changed returning when string
export function parse_param_placeholder(param: GT.FFIParamMacro, settings?: GT.LoadSettings): GT.FFIParam {
    if (typeof settings === 'undefined' || ! settings) {
        settings = {
            _UNICODE: true,
            _WIN64: process.arch === 'x64' ? true : false,
        };
    }
    else {
        if (typeof settings._WIN64 === 'undefined') {
            settings._WIN64 = process.arch === 'x64' ? true : false;
        }
        else {
            settings._WIN64 = !!settings._WIN64;
        }
        if (typeof settings._UNICODE === 'undefined') {
            settings._UNICODE = true;
        }
        else {
            settings._UNICODE = !! settings._UNICODE;
        }
    }
    if (typeof param === 'string') {
        return param;
    }


    let p: GT.FFIParam = '';

    if (param && Array.isArray(param)) {
        switch (param[0]) {<commit_msg>valid value of ps within parse_placeholder(ps)<commit_after>import * as Conf from './conf';
import * as GT from './types';


export function gen_api_opts(fnDef: GT.Win32FnDefMacro, fns?: GT.FnName[], settings?: GT.LoadSettings): GT.Win32FnDef {
    let opts = <GT.Win32FnDef> {};

    if (fns && Array.isArray(fns) && fns.length) {
        for (let fn of fns) {
            const ps: GT.FnParamsMacro = fnDef[fn];

            if (ps) {
                Object.defineProperty(opts, <string> fn, {
                    value: <GT.FnParams> parse_placeholder(ps, settings),
                    writable: false,
                    enumerable: true,
                    configurable: false,
                });
            }
        }
    }
    else {
        for (let fn in fnDef) {
            if ( ! {}.hasOwnProperty.call(fnDef, fn)) {
                continue;
            }
            const ps: GT.FnParamsMacro = fnDef[fn];

            if (ps) {
                Object.defineProperty(opts, <string> fn, {
                    value: <GT.FnParams> parse_placeholder(ps, settings),
                    writable: false,
                    enumerable: true,
                    configurable: false,
                });
            }
        }
    }

    return opts;
}

export function parse_placeholder(ps: GT.FnParamsMacro, settings?: GT.LoadSettings): GT.FnParams {
    if ( ! ps || ! Array.isArray(ps) || ps.length !== 2) {
        throw new Error('parse_placeholder(ps) value of ps invalid');
    }
    const returnParam: GT.FnRetTypeMacro = ps[0];
    const callParams: GT.FnCallParamsMacro = ps[1];
    let res = <GT.FnParams> new Array(2);

    // return param
    res[0] = parse_param_placeholder(returnParam, settings);

    // callling params
    // [ [placeholder, string, string],  [placeholder, string, string], string]
    let targetParams = <GT.FnCallParams> new Array();

    for (let i = 0, len = callParams.length; i < len; i++) {
        targetParams[i] = parse_param_placeholder(returnParam, settings);
    }
    res[1] = targetParams;

    return res;
}


// convert typeof array of param to string such like ['_WIN64_HOLDER_', 'int64', 'int32'], no changed returning when string
export function parse_param_placeholder(param: GT.FFIParamMacro, settings?: GT.LoadSettings): GT.FFIParam {
    if (typeof settings === 'undefined' || ! settings) {
        settings = {
            _UNICODE: true,
            _WIN64: process.arch === 'x64' ? true : false,
        };
    }
    else {
        if (typeof settings._WIN64 === 'undefined') {
            settings._WIN64 = process.arch === 'x64' ? true : false;
        }
        else {
            settings._WIN64 = !!settings._WIN64;
        }
        if (typeof settings._UNICODE === 'undefined') {
            settings._UNICODE = true;
        }
        else {
            settings._UNICODE = !! settings._UNICODE;
        }
    }
    if (typeof param === 'string') {
        return param;
    }

    let p: GT.FFIParam = '';

    if (param && Array.isArray(param)) {
        switch (param[0]) {
{'fraction_non_alphanumeric': 0.12683883622098724, 'fraction_numerical': 0.011114743380189604, 'mean_word_length': 1.880885122410546, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1500987', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1780, 'n_words': 445}