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


C++ VariableDeclaration::isStateVariable方法代码示例

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


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

示例1: visit

bool Compiler::visit(VariableDeclaration const& _variableDeclaration)
{
	solAssert(_variableDeclaration.isStateVariable(), "Compiler visit to non-state variable declaration.");
	CompilerContext::LocationSetter locationSetter(m_context, _variableDeclaration);

	m_context.startFunction(_variableDeclaration);
	m_breakTags.clear();
	m_continueTags.clear();

	ExpressionCompiler(m_context, m_optimize).appendStateVariableAccessor(_variableDeclaration);

	return false;
}
开发者ID:1600,项目名称:solidity,代码行数:13,代码来源:Compiler.cpp

示例2: endVisit

void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
{
    if (_variable.annotation().type)
        return;

    TypePointer type;
    if (_variable.typeName())
    {
        type = _variable.typeName()->annotation().type;
        using Location = VariableDeclaration::Location;
        Location varLoc = _variable.referenceLocation();
        DataLocation typeLoc = DataLocation::Memory;
        // References are forced to calldata for external function parameters (not return)
        // and memory for parameters (also return) of publicly visible functions.
        // They default to memory for function parameters and storage for local variables.
        // As an exception, "storage" is allowed for library functions.
        if (auto ref = dynamic_cast<ReferenceType const*>(type.get()))
        {
            bool isPointer = true;
            if (_variable.isExternalCallableParameter())
            {
                auto const& contract = dynamic_cast<ContractDefinition const&>(*_variable.scope()->scope());
                if (contract.isLibrary())
                {
                    if (varLoc == Location::Memory)
                        fatalTypeError(_variable.location(),
                                       "Location has to be calldata or storage for external "
                                       "library functions (remove the \"memory\" keyword)."
                                      );
                }
                else
                {
                    // force location of external function parameters (not return) to calldata
                    if (varLoc != Location::Default)
                        fatalTypeError(_variable.location(),
                                       "Location has to be calldata for external functions "
                                       "(remove the \"memory\" or \"storage\" keyword)."
                                      );
                }
                if (varLoc == Location::Default)
                    typeLoc = DataLocation::CallData;
                else
                    typeLoc = varLoc == Location::Memory ? DataLocation::Memory : DataLocation::Storage;
            }
            else if (_variable.isCallableParameter() && _variable.scope()->isPublic())
            {
                auto const& contract = dynamic_cast<ContractDefinition const&>(*_variable.scope()->scope());
                // force locations of public or external function (return) parameters to memory
                if (varLoc == Location::Storage && !contract.isLibrary())
                    fatalTypeError(_variable.location(),
                                   "Location has to be memory for publicly visible functions "
                                   "(remove the \"storage\" keyword)."
                                  );
                if (varLoc == Location::Default || !contract.isLibrary())
                    typeLoc = DataLocation::Memory;
                else
                    typeLoc = varLoc == Location::Memory ? DataLocation::Memory : DataLocation::Storage;
            }
            else
            {
                if (_variable.isConstant())
                {
                    if (varLoc != Location::Default && varLoc != Location::Memory)
                        fatalTypeError(
                            _variable.location(),
                            "Storage location has to be \"memory\" (or unspecified) for constants."
                        );
                    typeLoc = DataLocation::Memory;
                }
                else if (varLoc == Location::Default)
                    typeLoc = _variable.isCallableParameter() ? DataLocation::Memory : DataLocation::Storage;
                else
                    typeLoc = varLoc == Location::Memory ? DataLocation::Memory : DataLocation::Storage;
                isPointer = !_variable.isStateVariable();
            }

            type = ref->copyForLocation(typeLoc, isPointer);
        }
        else if (varLoc != Location::Default && !ref)
            fatalTypeError(_variable.location(), "Storage location can only be given for array or struct types.");

        if (!type)
            fatalTypeError(_variable.location(), "Invalid type name.");

    }
    else if (!_variable.canHaveAutoType())
        fatalTypeError(_variable.location(), "Explicit type needed.");
    // otherwise we have a "var"-declaration whose type is resolved by the first assignment

    _variable.annotation().type = type;
}
开发者ID:hrishioa,项目名称:solidity-doc-test,代码行数:91,代码来源:ReferencesResolver.cpp


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