Browse Source

LValueType of Expression Compiler is now CamelCase

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
368cc8ffea
  1. 32
      libsolidity/ExpressionCompiler.cpp
  2. 16
      libsolidity/ExpressionCompiler.h

32
libsolidity/ExpressionCompiler.cpp

@ -479,7 +479,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
{ {
StructType const& type = dynamic_cast<StructType const&>(*_memberAccess.getExpression().getType()); StructType const& type = dynamic_cast<StructType const&>(*_memberAccess.getExpression().getType());
m_context << type.getStorageOffsetOfMember(member) << eth::Instruction::ADD; m_context << type.getStorageOffsetOfMember(member) << eth::Instruction::ADD;
m_currentLValue = LValue(m_context, LValue::LValueType::STORAGE, *_memberAccess.getType()); m_currentLValue = LValue(m_context, LValue::LValueType::Storage, *_memberAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_memberAccess); m_currentLValue.retrieveValueIfLValueNotRequested(_memberAccess);
break; break;
} }
@ -515,7 +515,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
length += CompilerUtils(m_context).storeInMemory(length); length += CompilerUtils(m_context).storeInMemory(length);
m_context << u256(length) << u256(0) << eth::Instruction::SHA3; m_context << u256(length) << u256(0) << eth::Instruction::SHA3;
m_currentLValue = LValue(m_context, LValue::LValueType::STORAGE, *_indexAccess.getType()); m_currentLValue = LValue(m_context, LValue::LValueType::Storage, *_indexAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_indexAccess); m_currentLValue.retrieveValueIfLValueNotRequested(_indexAccess);
return false; return false;
@ -922,7 +922,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
m_context << eth::Instruction::DUP1 m_context << eth::Instruction::DUP1
<< structType->getStorageOffsetOfMember(names[i]) << structType->getStorageOffsetOfMember(names[i])
<< eth::Instruction::ADD; << eth::Instruction::ADD;
m_currentLValue = LValue(m_context, LValue::LValueType::STORAGE, *types[i]); m_currentLValue = LValue(m_context, LValue::LValueType::Storage, *types[i]);
m_currentLValue.retrieveValue(types[i], Location(), true); m_currentLValue.retrieveValue(types[i], Location(), true);
solAssert(types[i]->getSizeOnStack() == 1, "Returning struct elements with stack size != 1 not yet implemented."); solAssert(types[i]->getSizeOnStack() == 1, "Returning struct elements with stack size != 1 not yet implemented.");
m_context << eth::Instruction::SWAP1; m_context << eth::Instruction::SWAP1;
@ -934,7 +934,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
{ {
// simple value // simple value
solAssert(accessorType.getReturnParameterTypes().size() == 1, ""); solAssert(accessorType.getReturnParameterTypes().size() == 1, "");
m_currentLValue = LValue(m_context, LValue::LValueType::STORAGE, *returnType); m_currentLValue = LValue(m_context, LValue::LValueType::Storage, *returnType);
m_currentLValue.retrieveValue(returnType, Location(), true); m_currentLValue.retrieveValue(returnType, Location(), true);
retSizeOnStack = returnType->getSizeOnStack(); retSizeOnStack = returnType->getSizeOnStack();
} }
@ -948,7 +948,7 @@ ExpressionCompiler::LValue::LValue(CompilerContext& _compilerContext, LValueType
{ {
//@todo change the type cast for arrays //@todo change the type cast for arrays
solAssert(_dataType.getStorageSize() <= numeric_limits<unsigned>::max(), "The storage size of " +_dataType.toString() + " should fit in unsigned"); solAssert(_dataType.getStorageSize() <= numeric_limits<unsigned>::max(), "The storage size of " +_dataType.toString() + " should fit in unsigned");
if (m_type == LValueType::STORAGE) if (m_type == LValueType::Storage)
m_size = unsigned(_dataType.getStorageSize()); m_size = unsigned(_dataType.getStorageSize());
else else
m_size = unsigned(_dataType.getSizeOnStack()); m_size = unsigned(_dataType.getSizeOnStack());
@ -958,7 +958,7 @@ void ExpressionCompiler::LValue::retrieveValue(TypePointer const& _type, Locatio
{ {
switch (m_type) switch (m_type)
{ {
case LValueType::STACK: case LValueType::Stack:
{ {
unsigned stackPos = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset)); unsigned stackPos = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset));
if (stackPos >= 15) //@todo correct this by fetching earlier or moving to memory if (stackPos >= 15) //@todo correct this by fetching earlier or moving to memory
@ -968,10 +968,10 @@ void ExpressionCompiler::LValue::retrieveValue(TypePointer const& _type, Locatio
*m_context << eth::dupInstruction(stackPos + 1); *m_context << eth::dupInstruction(stackPos + 1);
break; break;
} }
case LValueType::STORAGE: case LValueType::Storage:
retrieveValueFromStorage(_type, _remove); retrieveValueFromStorage(_type, _remove);
break; break;
case LValueType::MEMORY: case LValueType::Memory:
if (!_type->isValueType()) if (!_type->isValueType())
break; // no distinction between value and reference for non-value types break; // no distinction between value and reference for non-value types
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location) BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
@ -1007,7 +1007,7 @@ void ExpressionCompiler::LValue::storeValue(Expression const& _expression, bool
{ {
switch (m_type) switch (m_type)
{ {
case LValueType::STACK: case LValueType::Stack:
{ {
unsigned stackDiff = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset)) - m_size + 1; unsigned stackDiff = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset)) - m_size + 1;
if (stackDiff > 16) if (stackDiff > 16)
@ -1020,7 +1020,7 @@ void ExpressionCompiler::LValue::storeValue(Expression const& _expression, bool
retrieveValue(_expression.getType(), _expression.getLocation()); retrieveValue(_expression.getType(), _expression.getLocation());
break; break;
} }
case LValueType::STORAGE: case LValueType::Storage:
if (!_expression.getType()->isValueType()) if (!_expression.getType()->isValueType())
break; // no distinction between value and reference for non-value types break; // no distinction between value and reference for non-value types
// stack layout: value value ... value ref // stack layout: value value ... value ref
@ -1045,7 +1045,7 @@ void ExpressionCompiler::LValue::storeValue(Expression const& _expression, bool
<< u256(1) << eth::Instruction::SWAP1 << eth::Instruction::SUB; << u256(1) << eth::Instruction::SWAP1 << eth::Instruction::SUB;
} }
break; break;
case LValueType::MEMORY: case LValueType::Memory:
if (!_expression.getType()->isValueType()) if (!_expression.getType()->isValueType())
break; // no distinction between value and reference for non-value types break; // no distinction between value and reference for non-value types
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation()) BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation())
@ -1062,7 +1062,7 @@ void ExpressionCompiler::LValue::setToZero(Expression const& _expression) const
{ {
switch (m_type) switch (m_type)
{ {
case LValueType::STACK: case LValueType::Stack:
{ {
unsigned stackDiff = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset)); unsigned stackDiff = m_context->baseToCurrentStackOffset(unsigned(m_baseStackOffset));
if (stackDiff > 16) if (stackDiff > 16)
@ -1074,7 +1074,7 @@ void ExpressionCompiler::LValue::setToZero(Expression const& _expression) const
<< eth::Instruction::POP; << eth::Instruction::POP;
break; break;
} }
case LValueType::STORAGE: case LValueType::Storage:
if (m_size == 0) if (m_size == 0)
*m_context << eth::Instruction::POP; *m_context << eth::Instruction::POP;
for (unsigned i = 0; i < m_size; ++i) for (unsigned i = 0; i < m_size; ++i)
@ -1086,7 +1086,7 @@ void ExpressionCompiler::LValue::setToZero(Expression const& _expression) const
<< u256(1) << eth::Instruction::ADD; << u256(1) << eth::Instruction::ADD;
} }
break; break;
case LValueType::MEMORY: case LValueType::Memory:
if (!_expression.getType()->isValueType()) if (!_expression.getType()->isValueType())
break; // no distinction between value and reference for non-value types break; // no distinction between value and reference for non-value types
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation()) BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_expression.getLocation())
@ -1111,7 +1111,7 @@ void ExpressionCompiler::LValue::retrieveValueIfLValueNotRequested(Expression co
void ExpressionCompiler::LValue::fromStateVariable(Declaration const& _varDecl, TypePointer const& _type) void ExpressionCompiler::LValue::fromStateVariable(Declaration const& _varDecl, TypePointer const& _type)
{ {
m_type = LValueType::STORAGE; m_type = LValueType::Storage;
solAssert(_type->getStorageSize() <= numeric_limits<unsigned>::max(), "The storage size of " + _type->toString() + " should fit in an unsigned"); solAssert(_type->getStorageSize() <= numeric_limits<unsigned>::max(), "The storage size of " + _type->toString() + " should fit in an unsigned");
*m_context << m_context->getStorageLocationOfVariable(_varDecl); *m_context << m_context->getStorageLocationOfVariable(_varDecl);
m_size = unsigned(_type->getStorageSize()); m_size = unsigned(_type->getStorageSize());
@ -1121,7 +1121,7 @@ void ExpressionCompiler::LValue::fromIdentifier(Identifier const& _identifier, D
{ {
if (m_context->isLocalVariable(&_declaration)) if (m_context->isLocalVariable(&_declaration))
{ {
m_type = LValueType::STACK; m_type = LValueType::Stack;
m_size = _identifier.getType()->getSizeOnStack(); m_size = _identifier.getType()->getSizeOnStack();
m_baseStackOffset = m_context->getBaseStackOffsetOfVariable(_declaration); m_baseStackOffset = m_context->getBaseStackOffsetOfVariable(_declaration);
} }

16
libsolidity/ExpressionCompiler.h

@ -120,7 +120,7 @@ private:
class LValue class LValue
{ {
public: public:
enum class LValueType { NONE, STACK, MEMORY, STORAGE }; enum class LValueType { None, Stack, Memory, Storage };
explicit LValue(CompilerContext& _compilerContext): m_context(&_compilerContext) { reset(); } explicit LValue(CompilerContext& _compilerContext): m_context(&_compilerContext) { reset(); }
LValue(CompilerContext& _compilerContext, LValueType _type, Type const& _dataType, unsigned _baseStackOffset = 0); LValue(CompilerContext& _compilerContext, LValueType _type, Type const& _dataType, unsigned _baseStackOffset = 0);
@ -130,15 +130,15 @@ private:
void fromIdentifier(Identifier const& _identifier, Declaration const& _declaration); void fromIdentifier(Identifier const& _identifier, Declaration const& _declaration);
/// Convenience function to set type for a state variable and retrieve the reference /// Convenience function to set type for a state variable and retrieve the reference
void fromStateVariable(Declaration const& _varDecl, TypePointer const& _type); void fromStateVariable(Declaration const& _varDecl, TypePointer const& _type);
void reset() { m_type = LValueType::NONE; m_baseStackOffset = 0; m_size = 0; } void reset() { m_type = LValueType::None; m_baseStackOffset = 0; m_size = 0; }
bool isValid() const { return m_type != LValueType::NONE; } bool isValid() const { return m_type != LValueType::None; }
bool isInOnStack() const { return m_type == LValueType::STACK; } bool isInOnStack() const { return m_type == LValueType::Stack; }
bool isInMemory() const { return m_type == LValueType::MEMORY; } bool isInMemory() const { return m_type == LValueType::Memory; }
bool isInStorage() const { return m_type == LValueType::STORAGE; } bool isInStorage() const { return m_type == LValueType::Storage; }
/// @returns true if this lvalue reference type occupies a slot on the stack. /// @returns true if this lvalue reference type occupies a slot on the stack.
bool storesReferenceOnStack() const { return m_type == LValueType::STORAGE || m_type == LValueType::MEMORY; } bool storesReferenceOnStack() const { return m_type == LValueType::Storage || m_type == LValueType::Memory; }
/// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true, /// 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 (note that is does not reset the type to @a NONE). /// also removes the reference from the stack (note that is does not reset the type to @a NONE).
@ -162,7 +162,7 @@ private:
void retrieveValueFromStorage(TypePointer const& _type, bool _remove = false) const; void retrieveValueFromStorage(TypePointer const& _type, bool _remove = false) const;
CompilerContext* m_context; CompilerContext* m_context;
LValueType m_type = LValueType::NONE; LValueType m_type = LValueType::None;
/// If m_type is STACK, this is base stack offset (@see /// If m_type is STACK, this is base stack offset (@see
/// CompilerContext::getBaseStackOffsetOfVariable) of a local variable. /// CompilerContext::getBaseStackOffsetOfVariable) of a local variable.
unsigned m_baseStackOffset = 0; unsigned m_baseStackOffset = 0;

Loading…
Cancel
Save