Ejemplo n.º 1
0
function genCast($func, $indent)
{
    global $current_server;
    $funcname = $func->name;
    $async = @$func->async;
    $args_set = parseArgs(@$func->args);
    // decode args
    $arg_count = count($args_set);
    if ($arg_count) {
        $argsType = getArgsType($funcname);
        echo "{$indent}{$argsType} _args;\n";
        echo "{$indent}const bool _fOk = cerl::getMailBody(_ar, _args);\n\n";
        echo "{$indent}CERL_ASSERT(_fOk && \"{$current_server}::_handle_cast - {$funcname}\");\n";
        echo "{$indent}if (_fOk)\n";
    } else {
        echo "{$indent}NS_CERL_IO::check_vt_null(_ar);\n";
    }
    $indent2 = $arg_count ? $indent . "\t" : $indent;
    echo "{$indent2}{$funcname}(caller";
    if ($arg_count == 1) {
        echo ", _args";
    } else {
        foreach ($args_set as $var => $tp) {
            echo ", _args.{$var}";
        }
    }
    echo ");\n";
}
Ejemplo n.º 2
0
function serializeArgsType($namespace, $func, $indent)
{
    global $cpp_keywords, $derived_types, $typeset, $current_server;
    $args = @$func->args;
    //there is not args anymore
    if (!$args) {
        return;
    }
    $args_set = parseArgs(@$func->args);
    $argsTyName = getArgsType($func->name);
    if (count($args_set) == 1) {
        return;
    }
    $tp_name = "{$current_server}::{$argsTyName}";
    if (@$derived_types[$current_server][$argsTyName]) {
        return;
    }
    //there are args here
    //put
    echo "{$indent}\nCERL_IO_BEGIN_PUTTER({$namespace}::{$argsTyName})\n";
    $indent2 = $indent . "\t";
    foreach ($args as $arg) {
        $var_member = "val.{$arg->name}";
        echo "{$indent2}NS_CERL_IO::put(os, {$var_member});\n";
    }
    echo "{$indent}CERL_IO_END_PUTTER()\n";
    //get
    echo "\n";
    echo "{$indent}CERL_IO_BEGIN_GETTER({$namespace}::{$argsTyName})\n";
    $indent2 = $indent . "\t";
    $indent3 = $indent2 . "\t";
    echo "{$indent2}return ";
    $i = 0;
    foreach ($args as $arg) {
        $var_member = "val.{$arg->name}";
        if ($i++ == 0) {
            echo "NS_CERL_IO::get(is, {$var_member})";
        } else {
            echo "\n{$indent3}&& NS_CERL_IO::get(is, {$var_member})";
        }
    }
    echo ";\n";
    echo "{$indent}CERL_IO_END_GETTER()\n";
    //copy
    //printPODTYPE($args);
    $podTrue = true;
    echo "\n{$indent}template <class AllocT>\n";
    echo "{$indent}inline void copy(AllocT& alloc, {$namespace}::{$argsTyName}& dest, const {$namespace}::{$argsTyName}& src)\n";
    echo "{$indent}{\n";
    echo "{$indent2}dest = src;\n";
    foreach ($args as $arg) {
        if (!isPOD($arg->type)) {
            echo "{$indent2}NS_CERL_IO::copy(alloc, dest.{$arg->name}, src.{$arg->name});\n";
            $podTrue = false;
        }
    }
    echo "{$indent}}\n";
    if ($podTrue) {
        echo "{$indent}CERL_PODTYPE({$namespace}::{$argsTyName}, true);\n";
    } else {
        echo "{$indent}CERL_PODTYPE({$namespace}::{$argsTyName}, false);\n";
    }
    //dump
    echo "\ntemplate<class LogT>\n";
    echo "inline void dump(LogT& log, const {$namespace}::{$argsTyName}& args)\n";
    echo "{\n";
    echo "\tNS_CERL_IO::dump(log, '{');\n";
    $i = 0;
    foreach ($args as $var) {
        if ($i++ == 0) {
            echo "\tNS_CERL_IO::dump(log, args.{$var->name});\n";
        } else {
            echo "\tNS_CERL_IO::dump(log, \", \");\n";
            echo "\tNS_CERL_IO::dump(log, args.{$var->name});\n";
        }
    }
    echo "\tNS_CERL_IO::dump(log, '}');\n";
    echo "}\n";
}
Ejemplo n.º 3
0
function processArgType($func, $indent)
{
    $name = $func->name;
    $args_set = parseArgs(@$func->args);
    $i = count($args_set);
    if ($i == 0) {
        return;
    } else {
        if ($i == 1) {
            foreach ($args_set as $var => $type) {
                $typename = mapType($type, "");
                $argsTyName = getArgsType($name);
                echo "\n{$indent}typedef {$typename} {$argsTyName};\n";
            }
        } else {
            echo "\n{$indent}typedef struct {\n";
            foreach ($args_set as $var => $type) {
                $typename = mapType($type, "");
                echo "{$indent}\t{$typename} {$var};\n";
            }
            $argsTyName = getArgsType($name);
            echo "{$indent}} {$argsTyName};\n";
        }
    }
}
Ejemplo n.º 4
0
function genSyncFuncDef($func, $indent)
{
    $name = $func->name;
    $async = @$func->async;
    $args_set = parseArgs(@$func->args);
    $retType = getRetType($name);
    if ($async) {
        echo "\n{$indent}/*[async]*/";
    }
    echo "\n{$indent}bool cerl_call {$name}(";
    if (!$async) {
        echo "cerl::ScopedAlloc& alloc";
        echo ",\n{$indent}\t{$retType}& _result";
    }
    $flag = 0;
    foreach ($args_set as $var => $type) {
        $typename = mapType($type, "&");
        if ($flag == 0 && $async) {
            echo "const {$typename} {$var}";
            $flag = 1;
        } else {
            echo ",\n{$indent}\tconst {$typename} {$var}";
        }
    }
    if (count($args_set) || !$async) {
        echo "\n{$indent}\t";
    }
    echo ")\n";
    echo "{$indent}{\n";
    if (count($args_set) > 1) {
        $argsTyName = getArgsType($name);
        echo "{$indent}\t{$argsTyName} _args = {";
        $j = 1;
        foreach ($args_set as $var => $type) {
            if ($j == 1) {
                echo "{$var}";
            } else {
                echo ", {$var}";
            }
            $j++;
        }
        echo "};\n";
    }
    if ($async) {
        if (count($args_set) == 0) {
            echo "{$indent}\treturn m_conn.dbg_cast0(this, (cerl::FID)code_{$name});\n";
        } else {
            if (count($args_set) == 1) {
                foreach ($args_set as $var => $type) {
                    break;
                }
                echo "{$indent}\treturn m_conn.dbg_cast(this, (cerl::FID)code_{$name}, {$var});\n";
            } else {
                echo "{$indent}\treturn m_conn.dbg_cast(this, (cerl::FID)code_{$name}, _args);\n";
            }
        }
    } else {
        if (count($args_set) == 0) {
            echo "{$indent}\treturn m_conn.dbg_call0(this, alloc, _result, (cerl::FID)code_{$name});\n";
        } else {
            if (count($args_set) == 1) {
                foreach ($args_set as $var => $type) {
                    break;
                }
                echo "{$indent}\treturn m_conn.dbg_call(this, alloc, _result, (cerl::FID)code_{$name}, {$var});\n";
            } else {
                echo "{$indent}\treturn m_conn.dbg_call(this, alloc, _result, (cerl::FID)code_{$name}, _args);\n";
            }
        }
    }
    echo "{$indent}}\n";
}