mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Calldata variables.
This commit is contained in:
parent
370350da07
commit
499cb0526f
@ -338,8 +338,14 @@ TypePointer FunctionDefinition::type() const
|
|||||||
TypePointer FunctionDefinition::typeViaContractName() const
|
TypePointer FunctionDefinition::typeViaContractName() const
|
||||||
{
|
{
|
||||||
if (annotation().contract->isLibrary())
|
if (annotation().contract->isLibrary())
|
||||||
return FunctionType(*this).asCallableFunction(true);
|
{
|
||||||
return TypeProvider::function(*this, FunctionType::Kind::Declaration);
|
if (isPublic())
|
||||||
|
return FunctionType(*this).asCallableFunction(true);
|
||||||
|
else
|
||||||
|
return TypeProvider::function(*this, FunctionType::Kind::Internal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return TypeProvider::function(*this, FunctionType::Kind::Declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
string FunctionDefinition::externalSignature() const
|
string FunctionDefinition::externalSignature() const
|
||||||
@ -616,18 +622,14 @@ set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() c
|
|||||||
|
|
||||||
if (!hasReferenceOrMappingType() || isStateVariable() || isEventParameter())
|
if (!hasReferenceOrMappingType() || isStateVariable() || isEventParameter())
|
||||||
return set<Location>{ Location::Unspecified };
|
return set<Location>{ Location::Unspecified };
|
||||||
else if (isExternalCallableParameter())
|
|
||||||
{
|
|
||||||
set<Location> locations{ Location::CallData };
|
|
||||||
if (isLibraryFunctionParameter())
|
|
||||||
locations.insert(Location::Storage);
|
|
||||||
return locations;
|
|
||||||
}
|
|
||||||
else if (isCallableOrCatchParameter())
|
else if (isCallableOrCatchParameter())
|
||||||
{
|
{
|
||||||
set<Location> locations{ Location::Memory };
|
set<Location> locations{ Location::Memory };
|
||||||
if (isInternalCallableParameter() || isLibraryFunctionParameter() || isTryCatchParameter())
|
if (isInternalCallableParameter() || isLibraryFunctionParameter() || isTryCatchParameter())
|
||||||
locations.insert(Location::Storage);
|
locations.insert(Location::Storage);
|
||||||
|
if (!isTryCatchParameter())
|
||||||
|
locations.insert(Location::CallData);
|
||||||
|
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
else if (isLocalVariable())
|
else if (isLocalVariable())
|
||||||
@ -642,8 +644,7 @@ set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() c
|
|||||||
case Type::Category::Mapping:
|
case Type::Category::Mapping:
|
||||||
return set<Location>{ Location::Storage };
|
return set<Location>{ Location::Storage };
|
||||||
default:
|
default:
|
||||||
// TODO: add Location::Calldata once implemented for local variables.
|
return set<Location>{ Location::Memory, Location::Storage, Location::CallData };
|
||||||
return set<Location>{ Location::Memory, Location::Storage };
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return dataLocations(typeName()->annotation().type, dataLocations);
|
return dataLocations(typeName()->annotation().type, dataLocations);
|
||||||
|
@ -1218,6 +1218,15 @@ void CompilerUtils::pushZeroValue(Type const& _type)
|
|||||||
m_context << u256(0);
|
m_context << u256(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (referenceType->location() == DataLocation::CallData)
|
||||||
|
{
|
||||||
|
solAssert(referenceType->sizeOnStack() == 1 || referenceType->sizeOnStack() == 2, "");
|
||||||
|
m_context << Instruction::CALLDATASIZE;
|
||||||
|
if (referenceType->sizeOnStack() == 2)
|
||||||
|
m_context << 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
solAssert(referenceType->location() == DataLocation::Memory, "");
|
solAssert(referenceType->location() == DataLocation::Memory, "");
|
||||||
if (auto arrayType = dynamic_cast<ArrayType const*>(&_type))
|
if (auto arrayType = dynamic_cast<ArrayType const*>(&_type))
|
||||||
if (arrayType->isDynamicallySized())
|
if (arrayType->isDynamicallySized())
|
||||||
|
@ -2238,6 +2238,27 @@ string YulUtilFunctions::zeroValueFunction(Type const& _type, bool _splitFunctio
|
|||||||
("functionName", functionName)
|
("functionName", functionName)
|
||||||
.render();
|
.render();
|
||||||
|
|
||||||
|
if (_type.dataStoredIn(DataLocation::CallData))
|
||||||
|
{
|
||||||
|
solAssert(
|
||||||
|
_type.category() == Type::Category::Struct ||
|
||||||
|
_type.category() == Type::Category::Array,
|
||||||
|
"");
|
||||||
|
Whiskers templ(R"(
|
||||||
|
function <functionName>() -> offset<?hasLength>, length</hasLength> {
|
||||||
|
offset := calldatasize()
|
||||||
|
<?hasLength> length := 0 </hasLength>
|
||||||
|
}
|
||||||
|
)");
|
||||||
|
templ("functionName", functionName);
|
||||||
|
templ("hasLength",
|
||||||
|
_type.category() == Type::Category::Array &&
|
||||||
|
dynamic_cast<ArrayType const&>(_type).isDynamicallySized()
|
||||||
|
);
|
||||||
|
|
||||||
|
return templ.render();
|
||||||
|
}
|
||||||
|
|
||||||
Whiskers templ(R"(
|
Whiskers templ(R"(
|
||||||
function <functionName>() -> ret {
|
function <functionName>() -> ret {
|
||||||
ret := <zeroValue>
|
ret := <zeroValue>
|
||||||
@ -2622,4 +2643,3 @@ string YulUtilFunctions::copyConstructorArgumentsToMemoryFunction(
|
|||||||
.render();
|
.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user