Implement function modifiers.

This commit is contained in:
chriseth
2020-12-17 17:00:51 +01:00
parent 9328503265
commit ccaa81fbe7
22 changed files with 220 additions and 8 deletions
@@ -40,8 +40,13 @@ class YulUtilFunctions;
class IRGeneratorForStatements: public ASTConstVisitor
{
public:
IRGeneratorForStatements(IRGenerationContext& _context, YulUtilFunctions& _utils):
IRGeneratorForStatements(
IRGenerationContext& _context,
YulUtilFunctions& _utils,
std::function<std::string()> _placeholderCallback = {}
):
m_context(_context),
m_placeholderCallback(std::move(_placeholderCallback)),
m_utils(_utils)
{}
@@ -58,6 +63,9 @@ public:
/// Calculates expression's value and returns variable where it was stored
IRVariable evaluateExpression(Expression const& _expression, Type const& _to);
/// Defines @a _var using the value of @a _value while performing type conversions, if required.
void define(IRVariable const& _var, IRVariable const& _value) { declareAssign(_var, _value, true); }
/// @returns the name of a function that computes the value of the given constant
/// and also generates the function.
std::string constantValueFunction(VariableDeclaration const& _constant);
@@ -66,6 +74,7 @@ public:
bool visit(Conditional const& _conditional) override;
bool visit(Assignment const& _assignment) override;
bool visit(TupleExpression const& _tuple) override;
void endVisit(PlaceholderStatement const& _placeholder) override;
bool visit(Block const& _block) override;
void endVisit(Block const& _block) override;
bool visit(IfStatement const& _ifStatement) override;
@@ -135,8 +144,7 @@ private:
/// @returns an output stream that can be used to define @a _var using a function call or
/// single stack slot expression.
std::ostream& define(IRVariable const& _var);
/// Defines @a _var using the value of @a _value while performing type conversions, if required.
void define(IRVariable const& _var, IRVariable const& _value) { declareAssign(_var, _value, true); }
/// Assigns @a _var to the value of @a _value while performing type conversions, if required.
void assign(IRVariable const& _var, IRVariable const& _value) { declareAssign(_var, _value, false); }
/// Declares variable @a _var.
@@ -189,6 +197,7 @@ private:
std::ostringstream m_code;
IRGenerationContext& m_context;
std::function<std::string()> m_placeholderCallback;
YulUtilFunctions& m_utils;
std::optional<IRLValue> m_currentLValue;
langutil::SourceLocation m_currentLocation;