mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fixup! previous reviews fixups
This commit is contained in:
parent
d233c66795
commit
0acab9d07e
@ -435,18 +435,21 @@ struct ReservedErrorSelector: public PostTypeChecker::Checker
|
|||||||
class LValueChecker: public ASTConstVisitor
|
class LValueChecker: public ASTConstVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LValueChecker(Identifier const& _identifier): m_declaration(_identifier.annotation().referencedDeclaration) {}
|
LValueChecker(Identifier const& _identifier):
|
||||||
|
m_declaration(_identifier.annotation().referencedDeclaration)
|
||||||
|
{}
|
||||||
bool willBeWrittenTo() const { return m_willBeWrittenTo; }
|
bool willBeWrittenTo() const { return m_willBeWrittenTo; }
|
||||||
void endVisit(Identifier const& _identifier) override
|
void endVisit(Identifier const& _identifier) override
|
||||||
{
|
{
|
||||||
|
solAssert(_identifier.annotation().referencedDeclaration);
|
||||||
if (
|
if (
|
||||||
_identifier.annotation().referencedDeclaration == m_declaration &&
|
*_identifier.annotation().referencedDeclaration == *m_declaration &&
|
||||||
_identifier.annotation().willBeWrittenTo
|
_identifier.annotation().willBeWrittenTo
|
||||||
)
|
)
|
||||||
m_willBeWrittenTo = true;
|
m_willBeWrittenTo = true;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
Declaration const* m_declaration;
|
Declaration const* m_declaration{};
|
||||||
bool m_willBeWrittenTo = false;
|
bool m_willBeWrittenTo = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -460,29 +463,27 @@ struct SimpleCounterForLoopChecker: public PostTypeChecker::Checker
|
|||||||
}
|
}
|
||||||
bool isSimpleCounterLoop(ForStatement const& _forStatement) const
|
bool isSimpleCounterLoop(ForStatement const& _forStatement) const
|
||||||
{
|
{
|
||||||
auto const* cond = dynamic_cast<BinaryOperation const*>(_forStatement.condition());
|
auto const* simpleCondition = dynamic_cast<BinaryOperation const*>(_forStatement.condition());
|
||||||
if (!cond || cond->getOperator() != Token::LessThan || cond->userDefinedFunctionType())
|
if (!simpleCondition || simpleCondition->getOperator() != Token::LessThan || simpleCondition->userDefinedFunctionType())
|
||||||
return false;
|
return false;
|
||||||
if (!_forStatement.loopExpression())
|
if (!_forStatement.loopExpression())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto const* post = dynamic_cast<UnaryOperation const*>(&_forStatement.loopExpression()->expression());
|
auto const* simplePostExpression = dynamic_cast<UnaryOperation const*>(&_forStatement.loopExpression()->expression());
|
||||||
// This matches both operators ++i and i++
|
// This matches both operators ++i and i++
|
||||||
if (!post || post->getOperator() != Token::Inc || post->userDefinedFunctionType())
|
if (!simplePostExpression || simplePostExpression->getOperator() != Token::Inc || simplePostExpression->userDefinedFunctionType())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto const* lhsIdentifier = dynamic_cast<Identifier const*>(&cond->leftExpression());
|
auto const* lhsIdentifier = dynamic_cast<Identifier const*>(&simpleCondition->leftExpression());
|
||||||
auto const* lhsType = dynamic_cast<IntegerType const*>(cond->leftExpression().annotation().type);
|
auto const* lhsIntegerType = dynamic_cast<IntegerType const*>(simpleCondition->leftExpression().annotation().type);
|
||||||
auto const *commonType = dynamic_cast<IntegerType const*>(cond->annotation().commonType);
|
auto const* commonIntegerType = dynamic_cast<IntegerType const*>(simpleCondition->annotation().commonType);
|
||||||
|
|
||||||
if (lhsIdentifier && lhsType && commonType && *lhsType == *commonType)
|
if (!lhsIdentifier || !lhsIntegerType || !commonIntegerType || *lhsIntegerType != *commonIntegerType)
|
||||||
{
|
|
||||||
LValueChecker lValueChecker{*lhsIdentifier};
|
|
||||||
_forStatement.body().accept(lValueChecker);
|
|
||||||
if (!lValueChecker.willBeWrittenTo())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
LValueChecker lhsLValueChecker{*lhsIdentifier};
|
||||||
|
_forStatement.body().accept(lhsLValueChecker);
|
||||||
|
return !lhsLValueChecker.willBeWrittenTo();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -491,11 +492,11 @@ struct SimpleCounterForLoopChecker: public PostTypeChecker::Checker
|
|||||||
|
|
||||||
PostTypeChecker::PostTypeChecker(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter)
|
PostTypeChecker::PostTypeChecker(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter)
|
||||||
{
|
{
|
||||||
m_checkers.push_back(make_shared<ConstStateVarCircularReferenceChecker>(_errorReporter));
|
m_checkers.push_back(std::make_shared<ConstStateVarCircularReferenceChecker>(_errorReporter));
|
||||||
m_checkers.push_back(make_shared<OverrideSpecifierChecker>(_errorReporter));
|
m_checkers.push_back(std::make_shared<OverrideSpecifierChecker>(_errorReporter));
|
||||||
m_checkers.push_back(make_shared<ModifierContextChecker>(_errorReporter));
|
m_checkers.push_back(std::make_shared<ModifierContextChecker>(_errorReporter));
|
||||||
m_checkers.push_back(make_shared<EventOutsideEmitErrorOutsideRevertChecker>(_errorReporter));
|
m_checkers.push_back(std::make_shared<EventOutsideEmitErrorOutsideRevertChecker>(_errorReporter));
|
||||||
m_checkers.push_back(make_shared<NoVariablesInInterfaceChecker>(_errorReporter));
|
m_checkers.push_back(std::make_shared<NoVariablesInInterfaceChecker>(_errorReporter));
|
||||||
m_checkers.push_back(make_shared<ReservedErrorSelector>(_errorReporter));
|
m_checkers.push_back(std::make_shared<ReservedErrorSelector>(_errorReporter));
|
||||||
m_checkers.push_back(make_shared<SimpleCounterForLoopChecker>(_errorReporter));
|
m_checkers.push_back(std::make_shared<SimpleCounterForLoopChecker>(_errorReporter));
|
||||||
}
|
}
|
||||||
|
@ -743,15 +743,15 @@ bool ASTJsonExporter::visit(WhileStatement const& _node)
|
|||||||
bool ASTJsonExporter::visit(ForStatement const& _node)
|
bool ASTJsonExporter::visit(ForStatement const& _node)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<pair<string, Json::Value>> attributes = {
|
std::vector<std::pair<std::string, Json::Value>> attributes = {
|
||||||
make_pair("initializationExpression", toJsonOrNull(_node.initializationExpression())),
|
std::make_pair("initializationExpression", toJsonOrNull(_node.initializationExpression())),
|
||||||
make_pair("condition", toJsonOrNull(_node.condition())),
|
std::make_pair("condition", toJsonOrNull(_node.condition())),
|
||||||
make_pair("loopExpression", toJsonOrNull(_node.loopExpression())),
|
std::make_pair("loopExpression", toJsonOrNull(_node.loopExpression())),
|
||||||
make_pair("body", toJson(_node.body()))
|
std::make_pair("body", toJson(_node.body()))
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_node.annotation().isSimpleCounterLoop.set())
|
if (_node.annotation().isSimpleCounterLoop.set())
|
||||||
attributes.emplace_back(make_pair("isSimpleCounterLoop", *_node.annotation().isSimpleCounterLoop));
|
attributes.emplace_back(std::make_pair("isSimpleCounterLoop", *_node.annotation().isSimpleCounterLoop));
|
||||||
|
|
||||||
setJsonNode(_node, "ForStatement", std::move(attributes));
|
setJsonNode(_node, "ForStatement", std::move(attributes));
|
||||||
return false;
|
return false;
|
||||||
|
@ -618,7 +618,7 @@ bool IRGeneratorForStatements::visit(ForStatement const& _forStatement)
|
|||||||
_forStatement.condition(),
|
_forStatement.condition(),
|
||||||
_forStatement.initializationExpression(),
|
_forStatement.initializationExpression(),
|
||||||
_forStatement.loopExpression(),
|
_forStatement.loopExpression(),
|
||||||
false,
|
false, // _isDoWhile
|
||||||
*_forStatement.annotation().isSimpleCounterLoop
|
*_forStatement.annotation().isSimpleCounterLoop
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user