aboutsummaryrefslogtreecommitdiffstats
path: root/LValue.h
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2015-02-26 03:27:55 +0800
committerChristian <c@ethdev.com>2015-02-28 05:52:19 +0800
commit87365f7612336c4c7f443aac568f8a515bc9bd35 (patch)
treee304628c5c65d0fb33082d1c8f9e49776fb0a70c /LValue.h
parenta5b4f18dd7291e403237061d5f9660db0299601d (diff)
downloaddexon-solidity-87365f7612336c4c7f443aac568f8a515bc9bd35.tar
dexon-solidity-87365f7612336c4c7f443aac568f8a515bc9bd35.tar.gz
dexon-solidity-87365f7612336c4c7f443aac568f8a515bc9bd35.tar.bz2
dexon-solidity-87365f7612336c4c7f443aac568f8a515bc9bd35.tar.lz
dexon-solidity-87365f7612336c4c7f443aac568f8a515bc9bd35.tar.xz
dexon-solidity-87365f7612336c4c7f443aac568f8a515bc9bd35.tar.zst
dexon-solidity-87365f7612336c4c7f443aac568f8a515bc9bd35.zip
Shortening of dynamic arrays.
Diffstat (limited to 'LValue.h')
-rw-r--r--LValue.h44
1 files changed, 35 insertions, 9 deletions
diff --git a/LValue.h b/LValue.h
index bfa681a4..1ed0ae01 100644
--- a/LValue.h
+++ b/LValue.h
@@ -24,6 +24,7 @@
#include <memory>
#include <libevmcore/SourceLocation.h>
+#include <libsolidity/ArrayUtils.h>
namespace dev
{
@@ -32,6 +33,7 @@ namespace solidity
class Declaration;
class Type;
+class ArrayType;
class CompilerContext;
/**
@@ -40,7 +42,7 @@ class CompilerContext;
class LValue
{
protected:
- LValue(CompilerContext& _compilerContext, std::shared_ptr<Type const> const& _dataType):
+ LValue(CompilerContext& _compilerContext, Type const& _dataType):
m_context(_compilerContext), m_dataType(_dataType) {}
public:
@@ -56,13 +58,14 @@ public:
/// Stack post: if !_move: value_of(lvalue_ref)
virtual void storeValue(Type const& _sourceType,
SourceLocation const& _location = SourceLocation(), bool _move = false) const = 0;
- /// Stores zero in the lvalue.
+ /// Stores zero in the lvalue. Removes the reference from the stack if @a _removeReference is true.
/// @a _location is the source location of the requested operation
- virtual void setToZero(SourceLocation const& _location = SourceLocation()) const = 0;
+ virtual void setToZero(
+ SourceLocation const& _location = SourceLocation(), bool _removeReference = true) const = 0;
protected:
CompilerContext& m_context;
- std::shared_ptr<Type const> m_dataType;
+ Type const& m_dataType;
};
/**
@@ -71,13 +74,14 @@ protected:
class StackVariable: public LValue
{
public:
- explicit StackVariable(CompilerContext& _compilerContext, Declaration const& _declaration);
+ StackVariable(CompilerContext& _compilerContext, Declaration const& _declaration);
virtual bool storesReferenceOnStack() const { return false; }
virtual void retrieveValue(SourceLocation const& _location, bool _remove = false) const override;
virtual void storeValue(Type const& _sourceType,
SourceLocation const& _location = SourceLocation(), bool _move = false) const override;
- virtual void setToZero(SourceLocation const& _location = SourceLocation()) const override;
+ virtual void setToZero(
+ SourceLocation const& _location = SourceLocation(), bool _removeReference = true) const override;
private:
/// Base stack offset (@see CompilerContext::getBaseStackOffsetOfVariable) of the local variable.
@@ -93,14 +97,15 @@ class StorageItem: public LValue
{
public:
/// Constructs the LValue and pushes the location of @a _declaration onto the stack.
- explicit StorageItem(CompilerContext& _compilerContext, Declaration const& _declaration);
+ StorageItem(CompilerContext& _compilerContext, Declaration const& _declaration);
/// Constructs the LValue and assumes that the storage reference is already on the stack.
- explicit StorageItem(CompilerContext& _compilerContext, std::shared_ptr<Type const> const& _type);
+ StorageItem(CompilerContext& _compilerContext, Type const& _type);
virtual bool storesReferenceOnStack() const { return true; }
virtual void retrieveValue(SourceLocation const& _location, bool _remove = false) const override;
virtual void storeValue(Type const& _sourceType,
SourceLocation const& _location = SourceLocation(), bool _move = false) const override;
- virtual void setToZero(SourceLocation const& _location = SourceLocation()) const override;
+ virtual void setToZero(
+ SourceLocation const& _location = SourceLocation(), bool _removeReference = true) const override;
private:
/// Number of stack elements occupied by the value (not the reference).
@@ -108,5 +113,26 @@ private:
unsigned m_size;
};
+/**
+ * Reference to the "length" member of a dynamically-sized array. This is an LValue with special
+ * semantics since assignments to it might reduce its length and thus arrays members have to be
+ * deleted.
+ */
+class StorageArrayLength: public LValue
+{
+public:
+ /// Constructs the LValue, assumes that the reference to the array head is already on the stack.
+ StorageArrayLength(CompilerContext& _compilerContext, ArrayType const& _arrayType);
+ virtual bool storesReferenceOnStack() const { return true; }
+ virtual void retrieveValue(SourceLocation const& _location, bool _remove = false) const override;
+ virtual void storeValue(Type const& _sourceType,
+ SourceLocation const& _location = SourceLocation(), bool _move = false) const override;
+ virtual void setToZero(
+ SourceLocation const& _location = SourceLocation(), bool _removeReference = true) const override;
+
+private:
+ ArrayType const& m_arrayType;
+};
+
}
}