当前位置: 首页>>代码示例>>C++>>正文


C++ FunctionDefinition::returnParameters方法代码示例

本文整理汇总了C++中FunctionDefinition::returnParameters方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionDefinition::returnParameters方法的具体用法?C++ FunctionDefinition::returnParameters怎么用?C++ FunctionDefinition::returnParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FunctionDefinition的用法示例。


在下文中一共展示了FunctionDefinition::returnParameters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: toFormalType

bool Why3Translator::visit(FunctionDefinition const& _function)
{
    if (!_function.isImplemented())
    {
        error(_function, "Unimplemented functions not supported.");
        return false;
    }
    if (_function.name().empty())
    {
        error(_function, "Fallback functions not supported.");
        return false;
    }
    if (!_function.modifiers().empty())
    {
        error(_function, "Modifiers not supported.");
        return false;
    }

    m_localVariables.clear();
    for (auto const& var: _function.parameters())
        m_localVariables[var->name()] = var.get();
    for (auto const& var: _function.returnParameters())
        m_localVariables[var->name()] = var.get();
    for (auto const& var: _function.localVariables())
        m_localVariables[var->name()] = var;

    add("let rec _" + _function.name());
    add(" (this: account)");
    for (auto const& param: _function.parameters())
    {
        string paramType;
        try
        {
            paramType = toFormalType(*param->annotation().type);
        }
        catch (NoFormalType &err)
        {
            string const* typeName = boost::get_error_info<errinfo_noFormalTypeFrom>(err);
            error(*param, "Parameter type \"" + (typeName ? *typeName : "") + "\" not supported.");
        }
        if (param->name().empty())
            error(*param, "Anonymous function parameters not supported.");
        add(" (arg_" + param->name() + ": " + paramType + ")");
    }
    add(":");

    indent();
    indent();
    string retString = "(";
    for (auto const& retParam: _function.returnParameters())
    {
        string paramType;
        try
        {
            paramType = toFormalType(*retParam->annotation().type);
        }
        catch (NoFormalType &err)
        {
            string const* typeName = boost::get_error_info<errinfo_noFormalTypeFrom>(err);
            error(*retParam, "Parameter type " + (typeName ? *typeName : "") + " not supported.");
        }
        if (retString.size() != 1)
            retString += ", ";
        retString += paramType;
    }
    add(retString + ")");
    unindent();

    addSourceFromDocStrings(_function.annotation());
    if (!m_currentContract.contract)
        error(_function, "Only functions inside contracts allowed.");
    addSourceFromDocStrings(m_currentContract.contract->annotation());

    if (_function.isDeclaredConst())
        addLine("ensures { (old this) = this }");
    else
        addLine("writes { this }");

    addLine("=");

    // store the prestate in the case we need to revert
    addLine("let prestate = {balance = this.balance; storage = " + copyOfStorage() + "} in ");

    // initialise local variables
    for (auto const& variable: _function.parameters())
        addLine("let _" + variable->name() + " = ref arg_" + variable->name() + " in");
    for (auto const& variable: _function.returnParameters())
    {
        if (variable->name().empty())
            error(*variable, "Unnamed return variables not yet supported.");
        string varType;
        try
        {
            varType = toFormalType(*variable->annotation().type);
        }
        catch (NoFormalType &err)
        {
            string const* typeNamePtr = boost::get_error_info<errinfo_noFormalTypeFrom>(err);
            error(*variable, "Type " + (typeNamePtr ? *typeNamePtr : "") + "in return parameter not yet supported.");
        }
//.........这里部分代码省略.........
开发者ID:M0rrisChang,项目名称:Smart-Contract,代码行数:101,代码来源:Why3Translator.cpp


注:本文中的FunctionDefinition::returnParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。