Browse Source

Styling changes for SourceLocation and friends

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
72f9ecd526
  1. 10
      libdevcore/SourceLocation.h
  2. 6
      libevmcore/Assembly.h
  3. 1
      libsolidity/Compiler.h
  4. 8
      libsolidity/CompilerContext.cpp
  5. 2
      libsolidity/CompilerContext.h
  6. 2
      libsolidity/ExpressionCompiler.cpp
  7. 6
      test/Assembly.cpp

10
libdevcore/SourceLocation.h

@ -39,12 +39,12 @@ struct SourceLocation
start(_start), end(_end), sourceName(_sourceName) { }
SourceLocation(): start(-1), end(-1) { }
SourceLocation(SourceLocation const& other):
start(other.start), end(other.end), sourceName(other.sourceName) {}
SourceLocation& operator=(SourceLocation const& other) { start = other.start; end = other.end; sourceName = other.sourceName; return *this;}
SourceLocation(SourceLocation const& _other):
start(_other.start), end(_other.end), sourceName(_other.sourceName) {}
SourceLocation& operator=(SourceLocation const& _other) { start = _other.start; end = _other.end; sourceName = _other.sourceName; return *this;}
bool operator==(SourceLocation const& other) const { return start == other.start && end == other.end;}
bool operator!=(SourceLocation const& other) const { return !(*this == other); }
bool operator==(SourceLocation const& _other) const { return start == _other.start && end == _other.end;}
bool operator!=(SourceLocation const& _other) const { return !operator==(_other); }
bool isEmpty() const { return start == -1 && end == -1; }

6
libevmcore/Assembly.h

@ -58,13 +58,13 @@ public:
int deposit() const;
bool match(AssemblyItem const& _i) const { return _i.m_type == UndefinedItem || (m_type == _i.m_type && (m_type != Operation || m_data == _i.m_data)); }
void setLocation(dev::SourceLocation const& _location) { m_location = _location;}
dev::SourceLocation const& getLocation() const { return m_location; }
void setLocation(SourceLocation const& _location) { m_location = _location;}
SourceLocation const& getLocation() const { return m_location; }
private:
AssemblyItemType m_type;
u256 m_data;
dev::SourceLocation m_location;
SourceLocation m_location;
};
using AssemblyItems = std::vector<AssemblyItem>;

1
libsolidity/Compiler.h

@ -41,6 +41,7 @@ public:
bytes getAssembledBytecode() { return m_context.getAssembledBytecode(m_optimize); }
bytes getRuntimeBytecode() { return m_runtimeContext.getAssembledBytecode(m_optimize);}
void streamAssembly(std::ostream& _stream) const { m_context.streamAssembly(_stream); }
/// Getters for compiler contexts. Only for testing purposes.
CompilerContext const& getContext() const { return m_context; }
CompilerContext const& getRuntimeContext() const { return m_runtimeContext; }

8
libsolidity/CompilerContext.cpp

@ -175,28 +175,28 @@ void CompilerContext::resetVisitedNodes(ASTNode const* _node)
CompilerContext& CompilerContext::operator<<(eth::AssemblyItem _item)
{
solAssert(m_visitedNodes.size() > 0, "No node on the visited stack");
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_item, m_visitedNodes.top()->getLocation());
return *this;
}
CompilerContext& CompilerContext::operator<<(eth::Instruction _instruction)
{
solAssert(m_visitedNodes.size() > 0, "No node on the visited stack");
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_instruction, m_visitedNodes.top()->getLocation());
return *this;
}
CompilerContext& CompilerContext::operator<<(u256 const& _value)
{
solAssert(m_visitedNodes.size() > 0, "No node on the visited stack");
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_value, m_visitedNodes.top()->getLocation());
return *this;
}
CompilerContext& CompilerContext::operator<<(bytes const& _data)
{
solAssert(m_visitedNodes.size() > 0, "No node on the visited stack");
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_data, m_visitedNodes.top()->getLocation());
return *this;
}

2
libsolidity/CompilerContext.h

@ -103,7 +103,7 @@ public:
/// Resets the stack of visited nodes with a new stack having only @c _node
void resetVisitedNodes(ASTNode const* _node);
/// Pops the stack of visited nodes
void popVisitedNodes() { m_visitedNodes.pop();}
void popVisitedNodes() { m_visitedNodes.pop(); }
/// Pushes an ASTNode to the stack of visited nodes
void pushVisitedNodes(ASTNode const* _node) { m_visitedNodes.push(_node); }

2
libsolidity/ExpressionCompiler.cpp

@ -165,7 +165,7 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
{
CompilerContext::LocationSetter locationSetter(m_context, &_binaryOperation);
CompilerContext::LocationSetter locationSetter(m_context, &_binaryOperation);
Expression const& leftExpression = _binaryOperation.getLeftExpression();
Expression const& rightExpression = _binaryOperation.getRightExpression();
Type const& commonType = _binaryOperation.getCommonType();

6
test/Assembly.cpp

@ -54,14 +54,10 @@ eth::AssemblyItems compileContract(const string& _sourceCode)
resolver.registerDeclarations(*sourceUnit);
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract));
}
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract));
}
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
@ -81,7 +77,7 @@ void checkAssemblyLocations(AssemblyItems const& _items, std::vector<SourceLocat
for (auto const& it: _items)
{
BOOST_CHECK_MESSAGE(it.getLocation() == _locations[i], std::string("Location mismatch for item" + i));
++ i;
++i;
}
}

Loading…
Cancel
Save