mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Initialise nesting depth of expression generator to zero.
This commit is contained in:
parent
ee9433f8c3
commit
079a9ab1f0
@ -429,7 +429,8 @@ string ExpressionStmtGenerator::visit()
|
|||||||
{
|
{
|
||||||
ExpressionGenerator exprGen{state};
|
ExpressionGenerator exprGen{state};
|
||||||
auto randomType = TypeProvider{state}.type();
|
auto randomType = TypeProvider{state}.type();
|
||||||
auto expression = exprGen.rOrLValueExpression({randomType, {}});
|
pair<SolidityTypePtr, string> randomTypeName = {randomType, {}};
|
||||||
|
auto expression = exprGen.rOrLValueExpression(randomTypeName);
|
||||||
if (expression.has_value())
|
if (expression.has_value())
|
||||||
return indentation() + expression.value().second + ";\n";
|
return indentation() + expression.value().second + ";\n";
|
||||||
else
|
else
|
||||||
@ -449,7 +450,8 @@ string IfStmtGenerator::visit()
|
|||||||
ostringstream ifStmt;
|
ostringstream ifStmt;
|
||||||
ExpressionGenerator exprGen{state};
|
ExpressionGenerator exprGen{state};
|
||||||
auto boolType = make_shared<BoolType>();
|
auto boolType = make_shared<BoolType>();
|
||||||
auto expression = exprGen.rOrLValueExpression({boolType, {}});
|
pair<SolidityTypePtr, string> boolTypeName = {boolType, {}};
|
||||||
|
auto expression = exprGen.rLValueOrLiteral(boolTypeName);
|
||||||
if (expression.has_value())
|
if (expression.has_value())
|
||||||
ifStmt << indentation()
|
ifStmt << indentation()
|
||||||
<< "if ("
|
<< "if ("
|
||||||
@ -614,7 +616,7 @@ vector<pair<SolidityTypePtr, string>> ExpressionGenerator::liveVariables()
|
|||||||
}
|
}
|
||||||
|
|
||||||
vector<pair<SolidityTypePtr, string>> ExpressionGenerator::liveVariables(
|
vector<pair<SolidityTypePtr, string>> ExpressionGenerator::liveVariables(
|
||||||
pair<SolidityTypePtr, string> _typeName
|
pair<SolidityTypePtr, string>& _typeName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto liveTypedVariables = state->currentFunctionState()->inputs |
|
auto liveTypedVariables = state->currentFunctionState()->inputs |
|
||||||
@ -652,7 +654,7 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::randomLValueExpress
|
|||||||
}
|
}
|
||||||
|
|
||||||
optional<pair<SolidityTypePtr, string>> ExpressionGenerator::lValueExpression(
|
optional<pair<SolidityTypePtr, string>> ExpressionGenerator::lValueExpression(
|
||||||
pair<SolidityTypePtr, string> _typeName
|
pair<SolidityTypePtr, string>& _typeName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Filter non-identical variables of the same type.
|
// Filter non-identical variables of the same type.
|
||||||
@ -737,8 +739,10 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::incDecOperation(
|
|||||||
bool _prefixOp
|
bool _prefixOp
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!holds_alternative<shared_ptr<IntegerType>>(_typeName.first))
|
solAssert(
|
||||||
return nullopt;
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first),
|
||||||
|
"Invalid inc/dec op"
|
||||||
|
);
|
||||||
|
|
||||||
auto lValue = lValueExpression(_typeName);
|
auto lValue = lValueExpression(_typeName);
|
||||||
if (!lValue.has_value())
|
if (!lValue.has_value())
|
||||||
@ -752,11 +756,90 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::incDecOperation(
|
|||||||
return lResult;
|
return lResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression(pair<SolidityTypePtr, string> _typeName)
|
ExpressionGenerator::RLValueExpr ExpressionGenerator::expressionType(SolidityTypePtr& _typePtr)
|
||||||
{
|
{
|
||||||
RLValueExpr exprType = static_cast<RLValueExpr>(
|
vector<RLValueExpr> permittedTypes;
|
||||||
state->uRandDist->distributionOneToN(static_cast<size_t>(RLValueExpr::RLMAX) - 1)
|
|
||||||
);
|
if (holds_alternative<shared_ptr<BoolType>>(_typePtr))
|
||||||
|
{
|
||||||
|
permittedTypes = {
|
||||||
|
RLValueExpr::VARREF,
|
||||||
|
RLValueExpr::LIT,
|
||||||
|
RLValueExpr::NOT,
|
||||||
|
RLValueExpr::LT,
|
||||||
|
RLValueExpr::GT,
|
||||||
|
RLValueExpr::LTE,
|
||||||
|
RLValueExpr::GTE,
|
||||||
|
RLValueExpr::EQ,
|
||||||
|
RLValueExpr::NEQ,
|
||||||
|
RLValueExpr::AND,
|
||||||
|
RLValueExpr::OR
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (holds_alternative<shared_ptr<FixedBytesType>>(_typePtr))
|
||||||
|
{
|
||||||
|
permittedTypes = {
|
||||||
|
RLValueExpr::VARREF,
|
||||||
|
RLValueExpr::LIT,
|
||||||
|
RLValueExpr::BITAND,
|
||||||
|
RLValueExpr::BITXOR,
|
||||||
|
RLValueExpr::BITOR,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (holds_alternative<shared_ptr<IntegerType>>(_typePtr))
|
||||||
|
{
|
||||||
|
bool signedType = get<shared_ptr<IntegerType>>(_typePtr)->signedType;
|
||||||
|
if (signedType)
|
||||||
|
permittedTypes = {
|
||||||
|
RLValueExpr::VARREF,
|
||||||
|
RLValueExpr::LIT,
|
||||||
|
RLValueExpr::PINC,
|
||||||
|
RLValueExpr::PDEC,
|
||||||
|
RLValueExpr::SINC,
|
||||||
|
RLValueExpr::SDEC,
|
||||||
|
RLValueExpr::BITNOT,
|
||||||
|
RLValueExpr::USUB,
|
||||||
|
RLValueExpr::MUL,
|
||||||
|
RLValueExpr::DIV,
|
||||||
|
RLValueExpr::MOD,
|
||||||
|
RLValueExpr::ADD,
|
||||||
|
RLValueExpr::BSUB,
|
||||||
|
RLValueExpr::BITAND,
|
||||||
|
RLValueExpr::BITXOR,
|
||||||
|
RLValueExpr::BITOR
|
||||||
|
};
|
||||||
|
else
|
||||||
|
permittedTypes = {
|
||||||
|
RLValueExpr::VARREF,
|
||||||
|
RLValueExpr::LIT,
|
||||||
|
RLValueExpr::PINC,
|
||||||
|
RLValueExpr::PDEC,
|
||||||
|
RLValueExpr::SINC,
|
||||||
|
RLValueExpr::SDEC,
|
||||||
|
RLValueExpr::BITNOT,
|
||||||
|
RLValueExpr::EXP,
|
||||||
|
RLValueExpr::MUL,
|
||||||
|
RLValueExpr::DIV,
|
||||||
|
RLValueExpr::MOD,
|
||||||
|
RLValueExpr::ADD,
|
||||||
|
RLValueExpr::BSUB,
|
||||||
|
RLValueExpr::SHL,
|
||||||
|
RLValueExpr::SHR,
|
||||||
|
RLValueExpr::BITAND,
|
||||||
|
RLValueExpr::BITXOR,
|
||||||
|
RLValueExpr::BITOR
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
permittedTypes = {RLValueExpr::VARREF, RLValueExpr::LIT};
|
||||||
|
}
|
||||||
|
return permittedTypes[state->uRandDist->distributionOneToN(permittedTypes.size()) - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression(pair<SolidityTypePtr, string>& _typeName)
|
||||||
|
{
|
||||||
|
RLValueExpr exprType = expressionType(_typeName.first);
|
||||||
|
|
||||||
if (deeplyNested())
|
if (deeplyNested())
|
||||||
return literal(_typeName.first);
|
return literal(_typeName.first);
|
||||||
@ -779,145 +862,153 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression
|
|||||||
case RLValueExpr::NOT:
|
case RLValueExpr::NOT:
|
||||||
{
|
{
|
||||||
// Logical not may only be applied to expressions of boolean type.
|
// Logical not may only be applied to expressions of boolean type.
|
||||||
if (!holds_alternative<shared_ptr<BoolType>>(_typeName.first))
|
solAssert(
|
||||||
return nullopt;
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
|
"Invalid not op"
|
||||||
|
);
|
||||||
op = "!";
|
op = "!";
|
||||||
return unaryExpression(_typeName, op);
|
return unaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::BITNOT:
|
case RLValueExpr::BITNOT:
|
||||||
{
|
{
|
||||||
// Bitwise not may only be applied to integer types.
|
// Bitwise not may only be applied to integer types.
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid bitnot op"
|
||||||
|
);
|
||||||
op = "~";
|
op = "~";
|
||||||
return unaryExpression(_typeName, op);
|
return unaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::USUB:
|
case RLValueExpr::USUB:
|
||||||
{
|
{
|
||||||
// Unary sub may only be applied to signed integer types
|
// Unary sub may only be applied to signed integer types
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first) &&
|
||||||
return nullopt;
|
get<shared_ptr<IntegerType>>(_typeName.first)->signedType,
|
||||||
bool signedType = get<shared_ptr<IntegerType>>(_typeName.first)->signedType;
|
"Invalid unary sub op"
|
||||||
if (!signedType)
|
);
|
||||||
return nullopt;
|
|
||||||
op = "-";
|
op = "-";
|
||||||
return unaryExpression(_typeName, op);
|
return unaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::EXP:
|
case RLValueExpr::EXP:
|
||||||
{
|
{
|
||||||
// Exponentiation may only be applied to unsigned integer types
|
// Exponentiation may only be applied to unsigned integer types
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first) &&
|
||||||
return nullopt;
|
!get<shared_ptr<IntegerType>>(_typeName.first)->signedType,
|
||||||
bool signedType = get<shared_ptr<IntegerType>>(_typeName.first)->signedType;
|
"Invalid exp op"
|
||||||
if (signedType)
|
);
|
||||||
return nullopt;
|
|
||||||
op = "**";
|
op = "**";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
// Arithmetic ops only be applied to integer types
|
// Arithmetic ops only be applied to integer types
|
||||||
case RLValueExpr::MUL:
|
case RLValueExpr::MUL:
|
||||||
{
|
{
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid mul op"
|
||||||
|
);
|
||||||
op = "*";
|
op = "*";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::DIV:
|
case RLValueExpr::DIV:
|
||||||
{
|
{
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid div op"
|
||||||
|
);
|
||||||
op = "/";
|
op = "/";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::MOD:
|
case RLValueExpr::MOD:
|
||||||
{
|
{
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid mod op"
|
||||||
|
);
|
||||||
op = "%";
|
op = "%";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::ADD:
|
case RLValueExpr::ADD:
|
||||||
{
|
{
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid add op"
|
||||||
|
);
|
||||||
op = "+";
|
op = "+";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::BSUB:
|
case RLValueExpr::BSUB:
|
||||||
{
|
{
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid sub op"
|
||||||
|
);
|
||||||
op = "-";
|
op = "-";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::SHL:
|
case RLValueExpr::SHL:
|
||||||
{
|
{
|
||||||
// Left shift may only be applied to unsigned integer types.
|
// Left shift may only be applied to unsigned integer types.
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first) &&
|
||||||
return nullopt;
|
!get<shared_ptr<IntegerType>>(_typeName.first)->signedType,
|
||||||
bool signedType = get<shared_ptr<IntegerType>>(_typeName.first)->signedType;
|
"Invalid shl op"
|
||||||
if (signedType)
|
);
|
||||||
return nullopt;
|
|
||||||
op = "<<";
|
op = "<<";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::SHR:
|
case RLValueExpr::SHR:
|
||||||
{
|
{
|
||||||
// Left shift may only be applied to unsigned integer types.
|
// Left shift may only be applied to unsigned integer types.
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
if (!integerType)
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first) &&
|
||||||
return nullopt;
|
!get<shared_ptr<IntegerType>>(_typeName.first)->signedType,
|
||||||
bool signedType = get<shared_ptr<IntegerType>>(_typeName.first)->signedType;
|
"Invalid shr op"
|
||||||
if (signedType)
|
);
|
||||||
return nullopt;
|
|
||||||
op = ">>";
|
op = ">>";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::BITAND:
|
case RLValueExpr::BITAND:
|
||||||
{
|
{
|
||||||
// Bitwise ops may only be applied to integer and fixed bytes types.
|
// Bitwise ops may only be applied to integer and fixed bytes types.
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
bool fixedBytesType = holds_alternative<shared_ptr<FixedBytesType>>(_typeName.first);
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first) ||
|
||||||
if (!(integerType || fixedBytesType))
|
holds_alternative<shared_ptr<FixedBytesType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid bitand op"
|
||||||
|
);
|
||||||
op = "&";
|
op = "&";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::BITOR:
|
case RLValueExpr::BITOR:
|
||||||
{
|
{
|
||||||
// Bitwise ops may only be applied to integer and fixed bytes types.
|
// Bitwise ops may only be applied to integer and fixed bytes types.
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
bool fixedBytesType = holds_alternative<shared_ptr<FixedBytesType>>(_typeName.first);
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first) ||
|
||||||
if (!(integerType || fixedBytesType))
|
holds_alternative<shared_ptr<FixedBytesType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid bitand op"
|
||||||
|
);
|
||||||
op = "|";
|
op = "|";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::BITXOR:
|
case RLValueExpr::BITXOR:
|
||||||
{
|
{
|
||||||
// Bitwise ops may only be applied to integer and fixed bytes types.
|
// Bitwise ops may only be applied to integer and fixed bytes types.
|
||||||
bool integerType = holds_alternative<shared_ptr<IntegerType>>(_typeName.first);
|
solAssert(
|
||||||
bool fixedBytesType = holds_alternative<shared_ptr<FixedBytesType>>(_typeName.first);
|
holds_alternative<shared_ptr<IntegerType>>(_typeName.first) ||
|
||||||
if (!(integerType || fixedBytesType))
|
holds_alternative<shared_ptr<FixedBytesType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid bitand op"
|
||||||
|
);
|
||||||
op = "^";
|
op = "^";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
}
|
}
|
||||||
case RLValueExpr::LT:
|
case RLValueExpr::LT:
|
||||||
{
|
{
|
||||||
// Comparison ops may be applied only if LHS type is boolean.
|
// Comparison ops may be applied only if LHS type is boolean.
|
||||||
bool boolType = holds_alternative<shared_ptr<BoolType>>(_typeName.first);
|
solAssert(
|
||||||
if (!boolType)
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid lt op"
|
||||||
|
);
|
||||||
|
|
||||||
// Types being compared could be integer, fixed bytes, address, or contract.
|
// Types being compared could be integer, fixed bytes, address, or contract.
|
||||||
auto operandType = TypeProvider{state}.type();
|
auto operandType = TypeProvider{state}.type();
|
||||||
@ -933,9 +1024,10 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression
|
|||||||
case RLValueExpr::GT:
|
case RLValueExpr::GT:
|
||||||
{
|
{
|
||||||
// Comparison ops may be applied only if LHS type is boolean.
|
// Comparison ops may be applied only if LHS type is boolean.
|
||||||
bool boolType = holds_alternative<shared_ptr<BoolType>>(_typeName.first);
|
solAssert(
|
||||||
if (!boolType)
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid gt op"
|
||||||
|
);
|
||||||
|
|
||||||
// Types being compared could be integer, fixed bytes, address, or contract.
|
// Types being compared could be integer, fixed bytes, address, or contract.
|
||||||
auto operandType = TypeProvider{state}.type();
|
auto operandType = TypeProvider{state}.type();
|
||||||
@ -951,9 +1043,10 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression
|
|||||||
case RLValueExpr::LTE:
|
case RLValueExpr::LTE:
|
||||||
{
|
{
|
||||||
// Comparison ops may be applied only if LHS type is boolean.
|
// Comparison ops may be applied only if LHS type is boolean.
|
||||||
bool boolType = holds_alternative<shared_ptr<BoolType>>(_typeName.first);
|
solAssert(
|
||||||
if (!boolType)
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid lte op"
|
||||||
|
);
|
||||||
|
|
||||||
// Types being compared could be integer, fixed bytes, address, or contract.
|
// Types being compared could be integer, fixed bytes, address, or contract.
|
||||||
auto operandType = TypeProvider{state}.type();
|
auto operandType = TypeProvider{state}.type();
|
||||||
@ -969,9 +1062,10 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression
|
|||||||
case RLValueExpr::GTE:
|
case RLValueExpr::GTE:
|
||||||
{
|
{
|
||||||
// Comparison ops may be applied only if LHS type is boolean.
|
// Comparison ops may be applied only if LHS type is boolean.
|
||||||
bool boolType = holds_alternative<shared_ptr<BoolType>>(_typeName.first);
|
solAssert(
|
||||||
if (!boolType)
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid gte op"
|
||||||
|
);
|
||||||
|
|
||||||
// Types being compared could be integer, fixed bytes, address, or contract.
|
// Types being compared could be integer, fixed bytes, address, or contract.
|
||||||
auto operandType = TypeProvider{state}.type();
|
auto operandType = TypeProvider{state}.type();
|
||||||
@ -987,9 +1081,10 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression
|
|||||||
case RLValueExpr::EQ:
|
case RLValueExpr::EQ:
|
||||||
{
|
{
|
||||||
// Comparison ops may be applied only if LHS type is boolean.
|
// Comparison ops may be applied only if LHS type is boolean.
|
||||||
bool boolType = holds_alternative<shared_ptr<BoolType>>(_typeName.first);
|
solAssert(
|
||||||
if (!boolType)
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid eq op"
|
||||||
|
);
|
||||||
|
|
||||||
// Types being compared could be integer, fixed bytes, address, or contract.
|
// Types being compared could be integer, fixed bytes, address, or contract.
|
||||||
auto operandType = TypeProvider{state}.type();
|
auto operandType = TypeProvider{state}.type();
|
||||||
@ -1005,9 +1100,10 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression
|
|||||||
case RLValueExpr::NEQ:
|
case RLValueExpr::NEQ:
|
||||||
{
|
{
|
||||||
// Comparison ops may be applied only if LHS type is boolean.
|
// Comparison ops may be applied only if LHS type is boolean.
|
||||||
bool boolType = holds_alternative<shared_ptr<BoolType>>(_typeName.first);
|
solAssert(
|
||||||
if (!boolType)
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid neq op"
|
||||||
|
);
|
||||||
|
|
||||||
// Types being compared could be integer, fixed bytes, address, or contract.
|
// Types being compared could be integer, fixed bytes, address, or contract.
|
||||||
auto operandType = TypeProvider{state}.type();
|
auto operandType = TypeProvider{state}.type();
|
||||||
@ -1023,9 +1119,10 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression
|
|||||||
case RLValueExpr::AND:
|
case RLValueExpr::AND:
|
||||||
{
|
{
|
||||||
// Logical ops may be applied only to boolean types.
|
// Logical ops may be applied only to boolean types.
|
||||||
bool boolType = holds_alternative<shared_ptr<BoolType>>(_typeName.first);
|
solAssert(
|
||||||
if (!boolType)
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid and op"
|
||||||
|
);
|
||||||
|
|
||||||
op = "&&";
|
op = "&&";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
@ -1033,9 +1130,10 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::rOrLValueExpression
|
|||||||
case RLValueExpr::OR:
|
case RLValueExpr::OR:
|
||||||
{
|
{
|
||||||
// Logical ops may be applied only to boolean types.
|
// Logical ops may be applied only to boolean types.
|
||||||
bool boolType = holds_alternative<shared_ptr<BoolType>>(_typeName.first);
|
solAssert(
|
||||||
if (!boolType)
|
holds_alternative<shared_ptr<BoolType>>(_typeName.first),
|
||||||
return nullopt;
|
"Invalid or op"
|
||||||
|
);
|
||||||
|
|
||||||
op = "||";
|
op = "||";
|
||||||
return binaryExpression(_typeName, op);
|
return binaryExpression(_typeName, op);
|
||||||
@ -1168,13 +1266,13 @@ SolidityTypePtr TypeProvider::type()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string FunctionCallGenerator::lhs(vector<pair<SolidityTypePtr, string>> _functionReturnTypeNames)
|
string FunctionCallGenerator::lhs(vector<pair<SolidityTypePtr, string>>& _functionReturnTypeNames)
|
||||||
{
|
{
|
||||||
ExpressionGenerator exprGen{state};
|
ExpressionGenerator exprGen{state};
|
||||||
ostringstream callStmtLhs;
|
ostringstream callStmtLhs;
|
||||||
|
|
||||||
auto assignToVars = _functionReturnTypeNames |
|
auto assignToVars = _functionReturnTypeNames |
|
||||||
ranges::views::transform([&exprGen](auto const& _item) -> pair<bool, optional<pair<SolidityTypePtr, string>>> {
|
ranges::views::transform([&exprGen](auto& _item) -> pair<bool, optional<pair<SolidityTypePtr, string>>> {
|
||||||
auto e = exprGen.lValueExpression(_item);
|
auto e = exprGen.lValueExpression(_item);
|
||||||
exprGen.resetNestingDepth();
|
exprGen.resetNestingDepth();
|
||||||
if (e.has_value())
|
if (e.has_value())
|
||||||
@ -1217,13 +1315,13 @@ string FunctionCallGenerator::lhs(vector<pair<SolidityTypePtr, string>> _functio
|
|||||||
return callStmtLhs.str();
|
return callStmtLhs.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<string> FunctionCallGenerator::rhs(vector<pair<SolidityTypePtr, string>> _functionInputTypeNames)
|
optional<string> FunctionCallGenerator::rhs(vector<pair<SolidityTypePtr, string>>& _functionInputTypeNames)
|
||||||
{
|
{
|
||||||
ExpressionGenerator exprGen{state};
|
ExpressionGenerator exprGen{state};
|
||||||
ostringstream callStmtRhs;
|
ostringstream callStmtRhs;
|
||||||
|
|
||||||
auto inputArguments = _functionInputTypeNames |
|
auto inputArguments = _functionInputTypeNames |
|
||||||
ranges::views::transform([&exprGen](auto const& _item) -> pair<bool, optional<pair<SolidityTypePtr, string>>>
|
ranges::views::transform([&exprGen](auto& _item) -> pair<bool, optional<pair<SolidityTypePtr, string>>>
|
||||||
{
|
{
|
||||||
auto e = exprGen.rOrLValueExpression(_item);
|
auto e = exprGen.rOrLValueExpression(_item);
|
||||||
exprGen.resetNestingDepth();
|
exprGen.resetNestingDepth();
|
||||||
|
@ -751,7 +751,9 @@ struct LiteralGenerator
|
|||||||
|
|
||||||
struct ExpressionGenerator
|
struct ExpressionGenerator
|
||||||
{
|
{
|
||||||
ExpressionGenerator(std::shared_ptr<TestState>& _state): state(_state)
|
ExpressionGenerator(std::shared_ptr<TestState>& _state):
|
||||||
|
state(_state),
|
||||||
|
nestingDepth(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
enum class RLValueExpr: size_t
|
enum class RLValueExpr: size_t
|
||||||
@ -788,16 +790,16 @@ struct ExpressionGenerator
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::optional<std::pair<SolidityTypePtr, std::string>> rOrLValueExpression(
|
std::optional<std::pair<SolidityTypePtr, std::string>> rOrLValueExpression(
|
||||||
std::pair<SolidityTypePtr, std::string> _typeName
|
std::pair<SolidityTypePtr, std::string>& _typeName
|
||||||
);
|
);
|
||||||
std::optional<std::pair<SolidityTypePtr, std::string>> literal(SolidityTypePtr _type);
|
std::optional<std::pair<SolidityTypePtr, std::string>> literal(SolidityTypePtr _type);
|
||||||
std::optional<std::pair<SolidityTypePtr, std::string>> randomLValueExpression();
|
std::optional<std::pair<SolidityTypePtr, std::string>> randomLValueExpression();
|
||||||
std::optional<std::pair<SolidityTypePtr, std::string>> lValueExpression(
|
std::optional<std::pair<SolidityTypePtr, std::string>> lValueExpression(
|
||||||
std::pair<SolidityTypePtr, std::string> _typeName
|
std::pair<SolidityTypePtr, std::string>& _typeName
|
||||||
);
|
);
|
||||||
std::vector<std::pair<SolidityTypePtr, std::string>> liveVariables();
|
std::vector<std::pair<SolidityTypePtr, std::string>> liveVariables();
|
||||||
std::vector<std::pair<SolidityTypePtr, std::string>> liveVariables(
|
std::vector<std::pair<SolidityTypePtr, std::string>> liveVariables(
|
||||||
std::pair<SolidityTypePtr, std::string> _typeName
|
std::pair<SolidityTypePtr, std::string>& _typeName
|
||||||
);
|
);
|
||||||
std::optional<std::pair<SolidityTypePtr, std::string>> unaryExpression(
|
std::optional<std::pair<SolidityTypePtr, std::string>> unaryExpression(
|
||||||
std::pair<SolidityTypePtr, std::string>& _typeName,
|
std::pair<SolidityTypePtr, std::string>& _typeName,
|
||||||
@ -815,6 +817,7 @@ struct ExpressionGenerator
|
|||||||
std::optional<std::pair<SolidityTypePtr, std::string>> rLValueOrLiteral(
|
std::optional<std::pair<SolidityTypePtr, std::string>> rLValueOrLiteral(
|
||||||
std::pair<SolidityTypePtr, std::string>& _typeName
|
std::pair<SolidityTypePtr, std::string>& _typeName
|
||||||
);
|
);
|
||||||
|
RLValueExpr expressionType(SolidityTypePtr& _typePtr);
|
||||||
|
|
||||||
void incrementNestingDepth()
|
void incrementNestingDepth()
|
||||||
{
|
{
|
||||||
@ -1173,8 +1176,8 @@ public:
|
|||||||
return "Function call generator";
|
return "Function call generator";
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string lhs(std::vector<std::pair<SolidityTypePtr, std::string>> _functionReturnTypeNames);
|
std::string lhs(std::vector<std::pair<SolidityTypePtr, std::string>>& _functionReturnTypeNames);
|
||||||
std::optional<std::string> rhs(std::vector<std::pair<SolidityTypePtr, std::string>> _functionInputTypeNames);
|
std::optional<std::string> rhs(std::vector<std::pair<SolidityTypePtr, std::string>>& _functionInputTypeNames);
|
||||||
std::string callStmt(std::shared_ptr<FunctionState> _callee);
|
std::string callStmt(std::shared_ptr<FunctionState> _callee);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user