mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Update OperationAnnotation to use SetOnce for userDefinedFunction
This commit is contained in:
parent
6fcd717ab4
commit
d124f83b88
@ -5,7 +5,7 @@ Language Features:
|
||||
|
||||
Compiler Features:
|
||||
* Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string.
|
||||
* Allow user-defined operators via ``using {f as +} for Typename;``.
|
||||
* Allow defining custom operators for user-defined value types and structs via ``using {f as +} for Typename;`` syntax.
|
||||
|
||||
|
||||
Bugfixes:
|
||||
|
@ -65,7 +65,7 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
|
||||
case Token::And:
|
||||
{
|
||||
visitNode(_operation);
|
||||
solAssert(!_operation.annotation().userDefinedFunction);
|
||||
solAssert(!_operation.annotation().userDefinedFunction.set());
|
||||
appendControlFlow(_operation.leftExpression());
|
||||
|
||||
auto nodes = splitFlow<2>();
|
||||
@ -75,14 +75,14 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (_operation.annotation().userDefinedFunction)
|
||||
if (_operation.annotation().userDefinedFunction.set())
|
||||
{
|
||||
visitNode(_operation);
|
||||
_operation.leftExpression().accept(*this);
|
||||
_operation.rightExpression().accept(*this);
|
||||
|
||||
solAssert(!m_currentNode->resolveFunctionCall(nullptr));
|
||||
m_currentNode->functionCall = _operation.annotation().userDefinedFunction;
|
||||
m_currentNode->functionCall = *_operation.annotation().userDefinedFunction;
|
||||
auto nextNode = newLabel();
|
||||
|
||||
connect(m_currentNode, nextNode);
|
||||
@ -99,11 +99,11 @@ bool ControlFlowBuilder::visit(UnaryOperation const& _operation)
|
||||
{
|
||||
solAssert(!!m_currentNode, "");
|
||||
|
||||
if (_operation.annotation().userDefinedFunction)
|
||||
if (_operation.annotation().userDefinedFunction.set())
|
||||
{
|
||||
visitNode(_operation);
|
||||
solAssert(!m_currentNode->resolveFunctionCall(nullptr));
|
||||
m_currentNode->functionCall = _operation.annotation().userDefinedFunction;
|
||||
m_currentNode->functionCall = *_operation.annotation().userDefinedFunction;
|
||||
|
||||
auto nextNode = newLabel();
|
||||
|
||||
|
@ -206,14 +206,14 @@ bool FunctionCallGraphBuilder::visit(MemberAccess const& _memberAccess)
|
||||
|
||||
bool FunctionCallGraphBuilder::visit(BinaryOperation const& _binaryOperation)
|
||||
{
|
||||
if (FunctionDefinition const* function = _binaryOperation.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = *_binaryOperation.annotation().userDefinedFunction)
|
||||
functionReferenced(*function, true /* called directly */);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FunctionCallGraphBuilder::visit(UnaryOperation const& _unaryOperation)
|
||||
{
|
||||
if (FunctionDefinition const* function = _unaryOperation.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = *_unaryOperation.annotation().userDefinedFunction)
|
||||
functionReferenced(*function, true /* called directly */);
|
||||
return true;
|
||||
}
|
||||
|
@ -333,14 +333,14 @@ void ViewPureChecker::reportFunctionCallMutability(StateMutability _mutability,
|
||||
|
||||
void ViewPureChecker::endVisit(BinaryOperation const& _binaryOperation)
|
||||
{
|
||||
if (_binaryOperation.annotation().userDefinedFunction)
|
||||
reportFunctionCallMutability(_binaryOperation.annotation().userDefinedFunction->stateMutability(), _binaryOperation.location());
|
||||
if (_binaryOperation.annotation().userDefinedFunction.set())
|
||||
reportFunctionCallMutability((*_binaryOperation.annotation().userDefinedFunction)->stateMutability(), _binaryOperation.location());
|
||||
}
|
||||
|
||||
void ViewPureChecker::endVisit(UnaryOperation const& _unaryOperation)
|
||||
{
|
||||
if (_unaryOperation.annotation().userDefinedFunction)
|
||||
reportFunctionCallMutability(_unaryOperation.annotation().userDefinedFunction->stateMutability(), _unaryOperation.location());
|
||||
if (_unaryOperation.annotation().userDefinedFunction.set())
|
||||
reportFunctionCallMutability((*_unaryOperation.annotation().userDefinedFunction)->stateMutability(), _unaryOperation.location());
|
||||
}
|
||||
|
||||
void ViewPureChecker::endVisit(FunctionCall const& _functionCall)
|
||||
|
@ -688,14 +688,19 @@ public:
|
||||
|
||||
/// @returns a list of functions or the single library.
|
||||
std::vector<ASTPointer<IdentifierPath>> const& functionsOrLibrary() const { return m_functions; }
|
||||
auto functionsAndOperators() const { return ranges::zip_view(m_functions, m_operators); }
|
||||
//auto functionsAndOperators() const { return ranges::zip_view(m_functions, m_operators); }
|
||||
ranges::zip_view<
|
||||
ranges::ref_view<const std::vector<std::shared_ptr<solidity::frontend::IdentifierPath>>>,
|
||||
ranges::ref_view<const std::vector<std::optional<solidity::langutil::Token>>>
|
||||
>
|
||||
functionsAndOperators() const { return ranges::zip_view(m_functions, m_operators); }
|
||||
bool usesBraces() const { return m_usesBraces; }
|
||||
bool global() const { return m_global; }
|
||||
|
||||
private:
|
||||
/// Either the single library or a list of functions.
|
||||
std::vector<ASTPointer<IdentifierPath>> m_functions;
|
||||
/// Operators, the functions are applied to.
|
||||
/// Operators, the functions from @a m_functions implement.
|
||||
std::vector<std::optional<Token>> m_operators;
|
||||
bool m_usesBraces;
|
||||
ASTPointer<TypeName> m_typeName;
|
||||
|
@ -314,7 +314,7 @@ struct MemberAccessAnnotation: ExpressionAnnotation
|
||||
|
||||
struct OperationAnnotation: ExpressionAnnotation
|
||||
{
|
||||
FunctionDefinition const* userDefinedFunction = nullptr;
|
||||
util::SetOnce<FunctionDefinition const*> userDefinedFunction;
|
||||
};
|
||||
|
||||
struct BinaryOperationAnnotation: OperationAnnotation
|
||||
|
@ -828,7 +828,7 @@ bool ASTJsonExporter::visit(UnaryOperation const& _node)
|
||||
make_pair("operator", TokenTraits::toString(_node.getOperator())),
|
||||
make_pair("subExpression", toJson(_node.subExpression()))
|
||||
};
|
||||
if (FunctionDefinition const* function = _node.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = *_node.annotation().userDefinedFunction)
|
||||
attributes.emplace_back("function", nodeId(*function));
|
||||
appendExpressionAttributes(attributes, _node.annotation());
|
||||
setJsonNode(_node, "UnaryOperation", std::move(attributes));
|
||||
@ -843,7 +843,7 @@ bool ASTJsonExporter::visit(BinaryOperation const& _node)
|
||||
make_pair("rightExpression", toJson(_node.rightExpression())),
|
||||
make_pair("commonType", typePointerToJson(_node.annotation().commonType)),
|
||||
};
|
||||
if (FunctionDefinition const* function = _node.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = *_node.annotation().userDefinedFunction)
|
||||
attributes.emplace_back("function", nodeId(*function));
|
||||
appendExpressionAttributes(attributes, _node.annotation());
|
||||
setJsonNode(_node, "BinaryOperation", std::move(attributes));
|
||||
|
@ -411,7 +411,7 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
|
||||
{
|
||||
CompilerContext::LocationSetter locationSetter(m_context, _unaryOperation);
|
||||
|
||||
if (FunctionDefinition const* function = _unaryOperation.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = *_unaryOperation.annotation().userDefinedFunction)
|
||||
{
|
||||
solAssert(
|
||||
function->isFree() || function->libraryFunction(),
|
||||
@ -538,7 +538,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
|
||||
CompilerContext::LocationSetter locationSetter(m_context, _binaryOperation);
|
||||
Expression const& leftExpression = _binaryOperation.leftExpression();
|
||||
Expression const& rightExpression = _binaryOperation.rightExpression();
|
||||
if (FunctionDefinition const* function =_binaryOperation.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = *_binaryOperation.annotation().userDefinedFunction)
|
||||
{
|
||||
solAssert(
|
||||
function->isFree() || function->libraryFunction(),
|
||||
|
@ -673,7 +673,7 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
|
||||
{
|
||||
setLocation(_unaryOperation);
|
||||
|
||||
if (FunctionDefinition const* function = _unaryOperation.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = *_unaryOperation.annotation().userDefinedFunction)
|
||||
{
|
||||
_unaryOperation.subExpression().accept(*this);
|
||||
setLocation(_unaryOperation);
|
||||
@ -817,7 +817,7 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
|
||||
{
|
||||
setLocation(_binOp);
|
||||
|
||||
if (FunctionDefinition const* function = _binOp.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = *_binOp.annotation().userDefinedFunction)
|
||||
{
|
||||
_binOp.leftExpression().accept(*this);
|
||||
_binOp.rightExpression().accept(*this);
|
||||
|
Loading…
Reference in New Issue
Block a user