Browse Source

LocationSetter in some extra places during Compiling

- Also adjusted the test, and fixed its error reporting
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
9f85e14ead
  1. 4
      libsolidity/Compiler.cpp
  2. 4
      libsolidity/CompilerContext.cpp
  3. 2
      libsolidity/CompilerContext.h
  4. 2
      libsolidity/ExpressionCompiler.cpp
  5. 5
      test/Assembly.cpp

4
libsolidity/Compiler.cpp

@ -129,6 +129,7 @@ void Compiler::packIntoContractCreator(ContractDefinition const& _contract, Comp
void Compiler::appendBaseConstructorCall(FunctionDefinition const& _constructor,
vector<ASTPointer<Expression>> const& _arguments)
{
CompilerContext::LocationSetter locationSetter(m_context, &_constructor);
FunctionType constructorType(_constructor);
eth::AssemblyItem returnLabel = m_context.pushNewTag();
for (unsigned i = 0; i < _arguments.size(); ++i)
@ -139,6 +140,7 @@ void Compiler::appendBaseConstructorCall(FunctionDefinition const& _constructor,
void Compiler::appendConstructorCall(FunctionDefinition const& _constructor)
{
CompilerContext::LocationSetter locationSetter(m_context, &_constructor);
eth::AssemblyItem returnTag = m_context.pushNewTag();
// copy constructor arguments from code to memory and then to stack, they are supplied after the actual program
unsigned argumentSize = 0;
@ -513,8 +515,8 @@ void Compiler::appendModifierOrFunctionCode()
else
{
ASTPointer<ModifierInvocation> const& modifierInvocation = m_currentFunction->getModifiers()[m_modifierDepth];
ModifierDefinition const& modifier = m_context.getFunctionModifier(modifierInvocation->getName()->getName());
CompilerContext::LocationSetter locationSetter(m_context, &modifier);
solAssert(modifier.getParameters().size() == modifierInvocation->getArguments().size(), "");
for (unsigned i = 0; i < modifier.getParameters().size(); ++i)
{

4
libsolidity/CompilerContext.cpp

@ -65,8 +65,8 @@ void CompilerContext::addVariable(VariableDeclaration const& _declaration,
void CompilerContext::addAndInitializeVariable(VariableDeclaration const& _declaration)
{
LocationSetter locationSetter(*this, &_declaration);
addVariable(_declaration);
int const size = _declaration.getType()->getSizeOnStack();
for (int i = 0; i < size; ++i)
*this << u256(0);
@ -173,7 +173,7 @@ void CompilerContext::resetVisitedNodes(ASTNode const* _node)
std::swap(m_visitedNodes, newStack);
}
CompilerContext& CompilerContext::operator<<(eth::AssemblyItem _item)
CompilerContext& CompilerContext::operator<<(eth::AssemblyItem const& _item)
{
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_item, m_visitedNodes.top()->getLocation());

2
libsolidity/CompilerContext.h

@ -108,7 +108,7 @@ public:
void pushVisitedNodes(ASTNode const* _node) { m_visitedNodes.push(_node); }
/// Append elements to the current instruction list and adjust @a m_stackOffset.
CompilerContext& operator<<(eth::AssemblyItem _item);
CompilerContext& operator<<(eth::AssemblyItem const& _item);
CompilerContext& operator<<(eth::Instruction _instruction);
CompilerContext& operator<<(u256 const& _value);
CompilerContext& operator<<(bytes const& _data);

2
libsolidity/ExpressionCompiler.cpp

@ -68,6 +68,7 @@ void ExpressionCompiler::appendStateVariableInitialization(CompilerContext& _con
void ExpressionCompiler::appendStateVariableInitialization(VariableDeclaration const& _varDecl)
{
CompilerContext::LocationSetter locationSetter(m_context, &_varDecl);
LValue var = LValue(m_context);
var.fromDeclaration(_varDecl, _varDecl.getValue()->getLocation());
var.storeValue(*_varDecl.getType(), _varDecl.getLocation());
@ -999,6 +1000,7 @@ void ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType,
void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& _varDecl)
{
CompilerContext::LocationSetter locationSetter(m_context, &_varDecl);
FunctionType accessorType(_varDecl);
unsigned length = 0;

5
test/Assembly.cpp

@ -76,7 +76,8 @@ void checkAssemblyLocations(AssemblyItems const& _items, std::vector<SourceLocat
BOOST_CHECK_EQUAL(_items.size(), _locations.size());
for (auto const& it: _items)
{
BOOST_CHECK_MESSAGE(it.getLocation() == _locations[i], std::string("Location mismatch for item" + i));
BOOST_CHECK_MESSAGE(it.getLocation() == _locations[i],
std::string("Location mismatch for assembly item ") + std::to_string(i));
++i;
}
@ -108,7 +109,7 @@ BOOST_AUTO_TEST_CASE(location_test)
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(0, 77, n),
SourceLocation(18, 75, n), SourceLocation(18, 75, n),
SourceLocation(18, 75, n), SourceLocation(40, 49, n),
SourceLocation(61, 70, n), SourceLocation(61, 70, n), SourceLocation(61, 70, n),
SourceLocation(), SourceLocation(),
SourceLocation(61, 70, n), SourceLocation(61, 70, n), SourceLocation(61, 70, n)

Loading…
Cancel
Save