Browse Source

Styling

cl-refactor
chriseth 10 years ago
parent
commit
7584f387d4
  1. 14
      libsolidity/CompilerUtils.cpp
  2. 21
      libsolidity/CompilerUtils.h
  3. 16
      libsolidity/LValue.cpp
  4. 48
      libsolidity/LValue.h

14
libsolidity/CompilerUtils.cpp

@ -33,8 +33,12 @@ namespace solidity
const unsigned int CompilerUtils::dataStartOffset = 4;
unsigned CompilerUtils::loadFromMemory(unsigned _offset, Type const& _type,
bool _fromCalldata, bool _padToWordBoundaries)
unsigned CompilerUtils::loadFromMemory(
unsigned _offset,
Type const& _type,
bool _fromCalldata,
bool _padToWordBoundaries
)
{
solAssert(_type.getCategory() != Type::Category::Array, "Unable to statically load dynamic type.");
m_context << u256(_offset);
@ -42,7 +46,11 @@ unsigned CompilerUtils::loadFromMemory(unsigned _offset, Type const& _type,
}
void CompilerUtils::loadFromMemoryDynamic(
Type const& _type, bool _fromCalldata, bool _padToWordBoundaries, bool _keepUpdatedMemoryOffset)
Type const& _type,
bool _fromCalldata,
bool _padToWordBoundaries,
bool _keepUpdatedMemoryOffset
)
{
solAssert(_type.getCategory() != Type::Category::Array, "Arrays not yet implemented.");
if (_keepUpdatedMemoryOffset)

21
libsolidity/CompilerUtils.h

@ -41,20 +41,31 @@ public:
/// @param _fromCalldata if true, load from calldata, not from memory
/// @param _padToWordBoundaries if true, assume the data is padded to word (32 byte) boundaries
/// @returns the number of bytes consumed in memory.
unsigned loadFromMemory(unsigned _offset, Type const& _type = IntegerType(256),
bool _fromCalldata = false, bool _padToWordBoundaries = false);
unsigned loadFromMemory(
unsigned _offset,
Type const& _type = IntegerType(256),
bool _fromCalldata = false,
bool _padToWordBoundaries = false
);
/// Dynamic version of @see loadFromMemory, expects the memory offset on the stack.
/// Stack pre: memory_offset
/// Stack post: value... (memory_offset+length)
void loadFromMemoryDynamic(Type const& _type, bool _fromCalldata = false,
bool _padToWordBoundaries = true, bool _keepUpdatedMemoryOffset = true);
void loadFromMemoryDynamic(
Type const& _type,
bool _fromCalldata = false,
bool _padToWordBoundaries = true,
bool _keepUpdatedMemoryOffset = true
);
/// Stores data from stack in memory.
/// @param _offset offset in memory
/// @param _type type of the data on the stack
/// @param _padToWordBoundaries if true, pad the data to word (32 byte) boundaries
/// @returns the number of bytes written to memory (can be different from _bytes if
/// _padToWordBoundaries is true)
unsigned storeInMemory(unsigned _offset, Type const& _type = IntegerType(256), bool _padToWordBoundaries = false);
unsigned storeInMemory(unsigned _offset,
Type const& _type = IntegerType(256),
bool _padToWordBoundaries = false
);
/// Dynamic version of @see storeInMemory, expects the memory offset below the value on the stack
/// and also updates that.
/// Stack pre: memory_offset value...

16
libsolidity/LValue.cpp

@ -242,7 +242,7 @@ StorageByteArrayElement::StorageByteArrayElement(CompilerContext& _compilerConte
void StorageByteArrayElement::retrieveValue(SourceLocation const&, bool _remove) const
{
// stack: ref bytenr
// stack: ref byte_number
if (_remove)
m_context << eth::Instruction::SWAP1 << eth::Instruction::SLOAD
<< eth::Instruction::SWAP1 << eth::Instruction::BYTE;
@ -255,15 +255,15 @@ void StorageByteArrayElement::storeValue(Type const&, SourceLocation const&, boo
{
//@todo optimize this
// stack: value ref bytenr
// stack: value ref byte_number
m_context << u256(31) << eth::Instruction::SUB << u256(0x100) << eth::Instruction::EXP;
// stack: value ref (1<<(8*(31-bytenr)))
// stack: value ref (1<<(8*(31-byte_number)))
m_context << eth::Instruction::DUP2 << eth::Instruction::SLOAD;
// stack: value ref (1<<(8*(31-bytenr))) old_full_value
// stack: value ref (1<<(8*(31-byte_number))) old_full_value
// clear byte in old value
m_context << eth::Instruction::DUP2 << u256(0xff) << eth::Instruction::MUL
<< eth::Instruction::NOT << eth::Instruction::AND;
// stack: value ref (1<<(32-bytenr)) old_full_value_with_cleared_byte
// stack: value ref (1<<(32-byte_number)) old_full_value_with_cleared_byte
m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP4 << eth::Instruction::MUL
<< eth::Instruction::OR;
// stack: value ref new_full_value
@ -274,13 +274,13 @@ void StorageByteArrayElement::storeValue(Type const&, SourceLocation const&, boo
void StorageByteArrayElement::setToZero(SourceLocation const&, bool _removeReference) const
{
// stack: ref bytenr
// stack: ref byte_number
if (!_removeReference)
m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP2;
m_context << u256(31) << eth::Instruction::SUB << u256(0x100) << eth::Instruction::EXP;
// stack: ref (1<<(8*(31-bytenr)))
// stack: ref (1<<(8*(31-byte_number)))
m_context << eth::Instruction::DUP2 << eth::Instruction::SLOAD;
// stack: ref (1<<(8*(31-bytenr))) old_full_value
// stack: ref (1<<(8*(31-byte_number))) old_full_value
// clear byte in old value
m_context << eth::Instruction::SWAP1 << u256(0xff) << eth::Instruction::MUL << eth::Instruction::AND;
// stack: ref old_full_value_with_cleared_byte

48
libsolidity/LValue.h

@ -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;
@ -78,10 +80,15 @@ public:
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.
@ -101,10 +108,15 @@ public:
/// Constructs the LValue and assumes that the storage reference is already on the stack.
StorageItem(CompilerContext& _compilerContext, Type const& _type);
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).
@ -123,10 +135,15 @@ public:
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 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;
};
/**
@ -140,10 +157,15 @@ public:
/// Constructs the LValue, assumes that the reference to the array head is already on the stack.
StorageArrayLength(CompilerContext& _compilerContext, ArrayType const& _arrayType);
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;

Loading…
Cancel
Save