aboutsummaryrefslogtreecommitdiffstats
path: root/LValue.h
diff options
context:
space:
mode:
Diffstat (limited to 'LValue.h')
-rw-r--r--LValue.h67
1 files changed, 52 insertions, 15 deletions
diff --git a/LValue.h b/LValue.h
index 1ed0ae01..c57c80e3 100644
--- a/LValue.h
+++ b/LValue.h
@@ -46,8 +46,8 @@ protected:
m_context(_compilerContext), m_dataType(_dataType) {}
public:
- /// @returns true if this lvalue reference type occupies a slot on the stack.
- virtual bool storesReferenceOnStack() const = 0;
+ /// @returns the number of stack slots occupied by the lvalue reference
+ virtual unsigned sizeOnStack() const { return 1; }
/// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true,
/// also removes the reference from the stack.
/// @a _location source location of the current expression, used for error reporting.
@@ -61,7 +61,9 @@ public:
/// 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(), bool _removeReference = true) const = 0;
+ SourceLocation const& _location = SourceLocation(),
+ bool _removeReference = true
+ ) const = 0;
protected:
CompilerContext& m_context;
@@ -76,12 +78,17 @@ class StackVariable: public LValue
public:
StackVariable(CompilerContext& _compilerContext, Declaration const& _declaration);
- virtual bool storesReferenceOnStack() const { return false; }
+ virtual unsigned sizeOnStack() const override { return 0; }
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 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;
+ SourceLocation const& _location = SourceLocation(),
+ bool _removeReference = true
+ ) const override;
private:
/// Base stack offset (@see CompilerContext::getBaseStackOffsetOfVariable) of the local variable.
@@ -100,12 +107,16 @@ public:
StorageItem(CompilerContext& _compilerContext, Declaration const& _declaration);
/// Constructs the LValue and assumes that the storage reference is already on the stack.
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 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;
+ SourceLocation const& _location = SourceLocation(),
+ bool _removeReference = true
+ ) const override;
private:
/// Number of stack elements occupied by the value (not the reference).
@@ -114,6 +125,28 @@ private:
};
/**
+ * Reference to a single byte inside a storage byte array.
+ * Stack: <storage_ref> <byte_number>
+ */
+class StorageByteArrayElement: public LValue
+{
+public:
+ /// Constructs the LValue and assumes that the storage reference is already on the stack.
+ StorageByteArrayElement(CompilerContext& _compilerContext);
+ virtual unsigned sizeOnStack() const override { return 2; }
+ 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;
+};
+
+/**
* 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.
@@ -123,12 +156,16 @@ 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 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;
+ SourceLocation const& _location = SourceLocation(),
+ bool _removeReference = true
+ ) const override;
private:
ArrayType const& m_arrayType;