aboutsummaryrefslogtreecommitdiffstats
path: root/ExpressionCompiler.h
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-11-07 09:06:37 +0800
committerChristian <c@ethdev.com>2014-11-08 03:02:57 +0800
commit64a4d77c8b8c559c6e9aad712f7288e4f107e946 (patch)
tree59a8bef45a09ac9b1682bf213886f713a12468c4 /ExpressionCompiler.h
parent4c8e670530675c7b7774b0d5355ee9aadd92f3a2 (diff)
downloaddexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.tar.gz
dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.tar.zst
dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.zip
State variables.
Diffstat (limited to 'ExpressionCompiler.h')
-rw-r--r--ExpressionCompiler.h54
1 files changed, 41 insertions, 13 deletions
diff --git a/ExpressionCompiler.h b/ExpressionCompiler.h
index d67814be..bd5a9f86 100644
--- a/ExpressionCompiler.h
+++ b/ExpressionCompiler.h
@@ -20,18 +20,25 @@
* Solidity AST to EVM bytecode compiler for expressions.
*/
+#include <libdevcore/Common.h>
#include <libsolidity/ASTVisitor.h>
namespace dev {
+namespace eth
+{
+class AssemblyItem; // forward
+}
namespace solidity {
class CompilerContext; // forward
class Type; // forward
class IntegerType; // forward
-/// Compiler for expressions, i.e. converts an AST tree whose root is an Expression into a stream
-/// of EVM instructions. It needs a compiler context that is the same for the whole compilation
-/// unit.
+/**
+ * Compiler for expressions, i.e. converts an AST tree whose root is an Expression into a stream
+ * of EVM instructions. It needs a compiler context that is the same for the whole compilation
+ * unit.
+ */
class ExpressionCompiler: private ASTVisitor
{
public:
@@ -42,7 +49,7 @@ public:
static void appendTypeConversion(CompilerContext& _context, Type const& _typeOnStack, Type const& _targetType);
private:
- ExpressionCompiler(CompilerContext& _compilerContext): m_currentLValue(nullptr), m_context(_compilerContext) {}
+ ExpressionCompiler(CompilerContext& _compilerContext): m_context(_compilerContext) {}
virtual bool visit(Assignment& _assignment) override;
virtual void endVisit(UnaryOperation& _unaryOperation) override;
@@ -72,15 +79,36 @@ private:
//// Appends code that cleans higher-order bits for integer types.
void appendHighBitsCleanup(IntegerType const& _typeOnStack);
- /// Stores the value on top of the stack in the current lvalue and copies that value to the
- /// top of the stack again
- void storeInLValue(Expression const& _expression);
- /// The same as storeInLValue but do not again retrieve the value to the top of the stack.
- void moveToLValue(Expression const& _expression);
- /// Returns the position of @a m_currentLValue in the stack, where 0 is the top of the stack.
- unsigned stackPositionOfLValue() const;
-
- Declaration* m_currentLValue;
+ /// Copies the value of the current lvalue to the top of the stack.
+ void retrieveLValueValue(Expression const& _expression);
+ /// Stores the value on top of the stack in the current lvalue. Removes it from the stack if
+ /// @a _move is true.
+ void storeInLValue(Expression const& _expression, bool _move = false);
+
+ /**
+ * Location of an lvalue, either in code (for a function) on the stack, in the storage or memory.
+ */
+ struct LValueLocation
+ {
+ enum LocationType { INVALID, CODE, STACK, MEMORY, STORAGE };
+
+ LValueLocation() { reset(); }
+ LValueLocation(LocationType _type, u256 const& _location): locationType(_type), location(_location) {}
+ void reset() { locationType = INVALID; location = 0; }
+ bool isValid() const { return locationType != INVALID; }
+ bool isInCode() const { return locationType == CODE; }
+ bool isInOnStack() const { return locationType == STACK; }
+ bool isInMemory() const { return locationType == MEMORY; }
+ bool isInStorage() const { return locationType == STORAGE; }
+
+ LocationType locationType;
+ /// Depending on the type, this is the id of a tag (code), the base offset of a stack
+ /// variable (@see CompilerContext::getBaseStackOffsetOfVariable) or the offset in
+ /// storage or memory.
+ u256 location;
+ };
+
+ LValueLocation m_currentLValue;
CompilerContext& m_context;
};