mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Isabelle abiv2 fuzzer: Add type string
This commit is contained in:
parent
d75821e068
commit
2e3cba996a
@ -195,7 +195,10 @@ pair<string, string> ProtoConverter::varDecl(
|
|||||||
typeStr,
|
typeStr,
|
||||||
((m_varCounter == 1) ? Delimiter::SKIP : Delimiter::ADD)
|
((m_varCounter == 1) ? Delimiter::SKIP : Delimiter::ADD)
|
||||||
);
|
);
|
||||||
|
appendToIsabelleTypeString(
|
||||||
|
tVisitor.isabelleTypeString(),
|
||||||
|
((m_varCounter == 1) ? Delimiter::SKIP : Delimiter::ADD)
|
||||||
|
);
|
||||||
// Update dyn param only if necessary
|
// Update dyn param only if necessary
|
||||||
if (tVisitor.isLastDynParamRightPadded())
|
if (tVisitor.isLastDynParamRightPadded())
|
||||||
m_isLastDynParamRightPadded = true;
|
m_isLastDynParamRightPadded = true;
|
||||||
@ -352,6 +355,14 @@ void ProtoConverter::appendTypedParamsPublic(
|
|||||||
.render();
|
.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProtoConverter::appendToIsabelleTypeString(
|
||||||
|
std::string const& _typeString,
|
||||||
|
Delimiter _delimiter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
m_isabelleTypeString << delimiterToString(_delimiter) << _typeString;
|
||||||
|
}
|
||||||
|
|
||||||
std::string ProtoConverter::typedParametersAsString(CalleeType _calleeType)
|
std::string ProtoConverter::typedParametersAsString(CalleeType _calleeType)
|
||||||
{
|
{
|
||||||
switch (_calleeType)
|
switch (_calleeType)
|
||||||
@ -628,6 +639,15 @@ pragma experimental ABIEncoderV2;)";
|
|||||||
.render();
|
.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ProtoConverter::isabelleTypeString() const
|
||||||
|
{
|
||||||
|
string typeString = m_isabelleTypeString.str();
|
||||||
|
if (!typeString.empty())
|
||||||
|
return "(" + typeString + ")";
|
||||||
|
else
|
||||||
|
return typeString;
|
||||||
|
}
|
||||||
|
|
||||||
string ProtoConverter::contractToString(Contract const& _input)
|
string ProtoConverter::contractToString(Contract const& _input)
|
||||||
{
|
{
|
||||||
visit(_input);
|
visit(_input);
|
||||||
@ -635,27 +655,44 @@ string ProtoConverter::contractToString(Contract const& _input)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Type visitor
|
/// Type visitor
|
||||||
|
void TypeVisitor::StructTupleString::addTypeStringToTuple(string& _typeString)
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
if (index > 1)
|
||||||
|
stream << ",";
|
||||||
|
stream << _typeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TypeVisitor::StructTupleString::addArrayBracketToType(string& _arrayBracket)
|
||||||
|
{
|
||||||
|
stream << _arrayBracket;
|
||||||
|
}
|
||||||
|
|
||||||
string TypeVisitor::visit(BoolType const&)
|
string TypeVisitor::visit(BoolType const&)
|
||||||
{
|
{
|
||||||
m_baseType = "bool";
|
m_baseType = "bool";
|
||||||
|
m_structTupleString.addTypeStringToTuple(m_baseType);
|
||||||
return m_baseType;
|
return m_baseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
string TypeVisitor::visit(IntegerType const& _type)
|
string TypeVisitor::visit(IntegerType const& _type)
|
||||||
{
|
{
|
||||||
m_baseType = getIntTypeAsString(_type);
|
m_baseType = getIntTypeAsString(_type);
|
||||||
|
m_structTupleString.addTypeStringToTuple(m_baseType);
|
||||||
return m_baseType;
|
return m_baseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
string TypeVisitor::visit(FixedByteType const& _type)
|
string TypeVisitor::visit(FixedByteType const& _type)
|
||||||
{
|
{
|
||||||
m_baseType = getFixedByteTypeAsString(_type);
|
m_baseType = getFixedByteTypeAsString(_type);
|
||||||
|
m_structTupleString.addTypeStringToTuple(m_baseType);
|
||||||
return m_baseType;
|
return m_baseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
string TypeVisitor::visit(AddressType const& _type)
|
string TypeVisitor::visit(AddressType const& _type)
|
||||||
{
|
{
|
||||||
m_baseType = getAddressTypeAsString(_type);
|
m_baseType = getAddressTypeAsString(_type);
|
||||||
|
m_structTupleString.addTypeStringToTuple(m_baseType);
|
||||||
return m_baseType;
|
return m_baseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,12 +703,13 @@ string TypeVisitor::visit(ArrayType const& _type)
|
|||||||
|
|
||||||
string baseType = visit(_type.t());
|
string baseType = visit(_type.t());
|
||||||
solAssert(!baseType.empty(), "");
|
solAssert(!baseType.empty(), "");
|
||||||
string arrayBraces = _type.is_static() ?
|
string arrayBracket = _type.is_static() ?
|
||||||
string("[") +
|
string("[") +
|
||||||
to_string(getStaticArrayLengthFromFuzz(_type.length())) +
|
to_string(getStaticArrayLengthFromFuzz(_type.length())) +
|
||||||
string("]") :
|
string("]") :
|
||||||
string("[]");
|
string("[]");
|
||||||
m_baseType += arrayBraces;
|
m_baseType += arrayBracket;
|
||||||
|
m_structTupleString.addArrayBracketToType(arrayBracket);
|
||||||
|
|
||||||
// If we don't know yet if the array will be dynamically encoded,
|
// If we don't know yet if the array will be dynamically encoded,
|
||||||
// check again. If we already know that it will be, there's no
|
// check again. If we already know that it will be, there's no
|
||||||
@ -679,13 +717,14 @@ string TypeVisitor::visit(ArrayType const& _type)
|
|||||||
if (!m_isLastDynParamRightPadded)
|
if (!m_isLastDynParamRightPadded)
|
||||||
m_isLastDynParamRightPadded = DynParamVisitor().visit(_type);
|
m_isLastDynParamRightPadded = DynParamVisitor().visit(_type);
|
||||||
|
|
||||||
return baseType + arrayBraces;
|
return baseType + arrayBracket;
|
||||||
}
|
}
|
||||||
|
|
||||||
string TypeVisitor::visit(DynamicByteArrayType const& _type)
|
string TypeVisitor::visit(DynamicByteArrayType const& _type)
|
||||||
{
|
{
|
||||||
m_isLastDynParamRightPadded = true;
|
m_isLastDynParamRightPadded = true;
|
||||||
m_baseType = bytesArrayTypeAsString(_type);
|
m_baseType = bytesArrayTypeAsString(_type);
|
||||||
|
m_structTupleString.addTypeStringToTuple(m_baseType);
|
||||||
return m_baseType;
|
return m_baseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -708,7 +747,8 @@ void TypeVisitor::structDefinition(StructType const& _type)
|
|||||||
to_string(m_structCounter) +
|
to_string(m_structCounter) +
|
||||||
" {"
|
" {"
|
||||||
);
|
);
|
||||||
|
// Start tuple of types with parenthesis
|
||||||
|
m_structTupleString.start();
|
||||||
// Increase indentation for struct fields
|
// Increase indentation for struct fields
|
||||||
m_indentation++;
|
m_indentation++;
|
||||||
for (auto const& t: _type.t())
|
for (auto const& t: _type.t())
|
||||||
@ -731,9 +771,13 @@ void TypeVisitor::structDefinition(StructType const& _type)
|
|||||||
("member", "m" + to_string(m_structFieldCounter++))
|
("member", "m" + to_string(m_structFieldCounter++))
|
||||||
.render()
|
.render()
|
||||||
);
|
);
|
||||||
|
string isabelleTypeStr = tVisitor.isabelleTypeString();
|
||||||
|
m_structTupleString.addTypeStringToTuple(isabelleTypeStr);
|
||||||
}
|
}
|
||||||
m_indentation--;
|
m_indentation--;
|
||||||
structDef += lineString("}");
|
structDef += lineString("}");
|
||||||
|
// End tuple of types with parenthesis
|
||||||
|
m_structTupleString.end();
|
||||||
m_structCounter++;
|
m_structCounter++;
|
||||||
m_structDef << structDef;
|
m_structDef << structDef;
|
||||||
m_indentation = wasIndentation;
|
m_indentation = wasIndentation;
|
||||||
|
@ -152,6 +152,7 @@ public:
|
|||||||
ProtoConverter(ProtoConverter const&) = delete;
|
ProtoConverter(ProtoConverter const&) = delete;
|
||||||
ProtoConverter(ProtoConverter&&) = delete;
|
ProtoConverter(ProtoConverter&&) = delete;
|
||||||
std::string contractToString(Contract const& _input);
|
std::string contractToString(Contract const& _input);
|
||||||
|
std::string isabelleTypeString() const;
|
||||||
private:
|
private:
|
||||||
enum class Delimiter
|
enum class Delimiter
|
||||||
{
|
{
|
||||||
@ -287,6 +288,13 @@ private:
|
|||||||
Delimiter _delimiter
|
Delimiter _delimiter
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// Append type name to type string meant to be
|
||||||
|
/// passed to Isabelle coder API.
|
||||||
|
void appendToIsabelleTypeString(
|
||||||
|
std::string const& _typeString,
|
||||||
|
Delimiter _delimiter
|
||||||
|
);
|
||||||
|
|
||||||
/// Returns a Solidity variable declaration statement
|
/// Returns a Solidity variable declaration statement
|
||||||
/// @param _type: string containing Solidity type of the
|
/// @param _type: string containing Solidity type of the
|
||||||
/// variable to be declared.
|
/// variable to be declared.
|
||||||
@ -369,6 +377,8 @@ private:
|
|||||||
/// Contains typed parameter list to be passed to callee functions
|
/// Contains typed parameter list to be passed to callee functions
|
||||||
std::ostringstream m_typedParamsExternal;
|
std::ostringstream m_typedParamsExternal;
|
||||||
std::ostringstream m_typedParamsPublic;
|
std::ostringstream m_typedParamsPublic;
|
||||||
|
/// Contains type string to be passed to Isabelle API
|
||||||
|
std::ostringstream m_isabelleTypeString;
|
||||||
/// Contains type stream to be used in returndata coder function
|
/// Contains type stream to be used in returndata coder function
|
||||||
/// signature
|
/// signature
|
||||||
std::ostringstream m_types;
|
std::ostringstream m_types;
|
||||||
@ -630,7 +640,31 @@ public:
|
|||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
std::string isabelleTypeString()
|
||||||
|
{
|
||||||
|
return m_structTupleString.stream.str();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
|
struct StructTupleString
|
||||||
|
{
|
||||||
|
StructTupleString() = default;
|
||||||
|
unsigned index = 0;
|
||||||
|
std::ostringstream stream;
|
||||||
|
void start()
|
||||||
|
{
|
||||||
|
stream << "(";
|
||||||
|
}
|
||||||
|
void end()
|
||||||
|
{
|
||||||
|
stream << ")";
|
||||||
|
}
|
||||||
|
std::string operator()()
|
||||||
|
{
|
||||||
|
return stream.str();
|
||||||
|
}
|
||||||
|
void addTypeStringToTuple(std::string& _typeString);
|
||||||
|
void addArrayBracketToType(std::string& _arrayBracket);
|
||||||
|
};
|
||||||
void structDefinition(StructType const&);
|
void structDefinition(StructType const&);
|
||||||
|
|
||||||
std::string indentation()
|
std::string indentation()
|
||||||
@ -641,9 +675,11 @@ private:
|
|||||||
{
|
{
|
||||||
return indentation() + _line + "\n";
|
return indentation() + _line + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string m_baseType;
|
std::string m_baseType;
|
||||||
std::ostringstream m_structDef;
|
std::ostringstream m_structDef;
|
||||||
|
/// Utility type for conveniently composing a tuple
|
||||||
|
/// string for struct types.
|
||||||
|
StructTupleString m_structTupleString;
|
||||||
unsigned m_indentation;
|
unsigned m_indentation;
|
||||||
unsigned m_structCounter;
|
unsigned m_structCounter;
|
||||||
unsigned m_structStartCounter;
|
unsigned m_structStartCounter;
|
||||||
|
Loading…
Reference in New Issue
Block a user