mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove error reporter from code generation phase.
This commit is contained in:
@@ -73,14 +73,14 @@ void CodeTransform::operator()(Assignment const& _assignment)
|
||||
{
|
||||
visitExpression(*_assignment.value);
|
||||
m_assembly.setSourceLocation(_assignment.location);
|
||||
generateAssignment(_assignment.variableName, _assignment.location);
|
||||
generateAssignment(_assignment.variableName);
|
||||
checkStackHeight(&_assignment);
|
||||
}
|
||||
|
||||
void CodeTransform::operator()(StackAssignment const& _assignment)
|
||||
{
|
||||
m_assembly.setSourceLocation(_assignment.location);
|
||||
generateAssignment(_assignment.variableName, _assignment.location);
|
||||
generateAssignment(_assignment.variableName);
|
||||
checkStackHeight(&_assignment);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ void CodeTransform::operator()(assembly::Identifier const& _identifier)
|
||||
if (m_scope->lookup(_identifier.name, Scope::NonconstVisitor(
|
||||
[=](Scope::Variable& _var)
|
||||
{
|
||||
if (int heightDiff = variableHeightDiff(_var, _identifier.location, false))
|
||||
if (int heightDiff = variableHeightDiff(_var, false))
|
||||
m_assembly.appendInstruction(solidity::dupInstruction(heightDiff));
|
||||
else
|
||||
// Store something to balance the stack
|
||||
@@ -320,7 +320,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
|
||||
m_assembly.appendConstant(u256(0));
|
||||
}
|
||||
|
||||
CodeTransform(m_errorReporter, m_assembly, m_info, m_evm15, m_identifierAccess, localStackAdjustment)
|
||||
CodeTransform(m_assembly, m_info, m_evm15, m_identifierAccess, localStackAdjustment)
|
||||
.run(_function.body);
|
||||
|
||||
{
|
||||
@@ -366,7 +366,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
|
||||
|
||||
void CodeTransform::operator()(Block const& _block)
|
||||
{
|
||||
CodeTransform(m_errorReporter, m_assembly, m_info, m_evm15, m_identifierAccess, m_stackAdjustment).run(_block);
|
||||
CodeTransform(m_assembly, m_info, m_evm15, m_identifierAccess, m_stackAdjustment).run(_block);
|
||||
}
|
||||
|
||||
AbstractAssembly::LabelID CodeTransform::labelFromIdentifier(Identifier const& _identifier)
|
||||
@@ -394,14 +394,14 @@ void CodeTransform::visitExpression(Statement const& _expression)
|
||||
expectDeposit(1, height);
|
||||
}
|
||||
|
||||
void CodeTransform::generateAssignment(Identifier const& _variableName, SourceLocation const& _location)
|
||||
void CodeTransform::generateAssignment(Identifier const& _variableName)
|
||||
{
|
||||
solAssert(m_scope, "");
|
||||
auto var = m_scope->lookup(_variableName.name);
|
||||
if (var)
|
||||
{
|
||||
Scope::Variable const& _var = boost::get<Scope::Variable>(*var);
|
||||
if (int heightDiff = variableHeightDiff(_var, _location, true))
|
||||
if (int heightDiff = variableHeightDiff(_var, true))
|
||||
m_assembly.appendInstruction(solidity::swapInstruction(heightDiff - 1));
|
||||
m_assembly.appendInstruction(solidity::Instruction::POP);
|
||||
}
|
||||
@@ -415,14 +415,12 @@ void CodeTransform::generateAssignment(Identifier const& _variableName, SourceLo
|
||||
}
|
||||
}
|
||||
|
||||
int CodeTransform::variableHeightDiff(solidity::assembly::Scope::Variable const& _var, SourceLocation const& _location, bool _forSwap)
|
||||
int CodeTransform::variableHeightDiff(solidity::assembly::Scope::Variable const& _var, bool _forSwap)
|
||||
{
|
||||
int heightDiff = m_assembly.stackHeight() - _var.stackHeight;
|
||||
if (heightDiff <= (_forSwap ? 1 : 0) || heightDiff > (_forSwap ? 17 : 16))
|
||||
{
|
||||
//@TODO move this to analysis phase.
|
||||
m_errorReporter.typeError(
|
||||
_location,
|
||||
solUnimplemented(
|
||||
"Variable inaccessible, too deep inside stack (" + boost::lexical_cast<string>(heightDiff) + ")"
|
||||
);
|
||||
return 0;
|
||||
|
||||
@@ -61,12 +61,11 @@ public:
|
||||
/// Create the code transformer.
|
||||
/// @param _identifierAccess used to resolve identifiers external to the inline assembly
|
||||
CodeTransform(
|
||||
solidity::ErrorReporter& _errorReporter,
|
||||
julia::AbstractAssembly& _assembly,
|
||||
solidity::assembly::AsmAnalysisInfo& _analysisInfo,
|
||||
bool _evm15 = false,
|
||||
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess()
|
||||
): CodeTransform(_errorReporter, _assembly, _analysisInfo, _evm15, _identifierAccess, _assembly.stackHeight())
|
||||
): CodeTransform(_assembly, _analysisInfo, _evm15, _identifierAccess, _assembly.stackHeight())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -75,14 +74,12 @@ public:
|
||||
|
||||
protected:
|
||||
CodeTransform(
|
||||
solidity::ErrorReporter& _errorReporter,
|
||||
julia::AbstractAssembly& _assembly,
|
||||
solidity::assembly::AsmAnalysisInfo& _analysisInfo,
|
||||
bool _evm15,
|
||||
ExternalIdentifierAccess const& _identifierAccess,
|
||||
int _stackAdjustment
|
||||
):
|
||||
m_errorReporter(_errorReporter),
|
||||
m_assembly(_assembly),
|
||||
m_info(_analysisInfo),
|
||||
m_evm15(_evm15),
|
||||
@@ -109,12 +106,12 @@ private:
|
||||
/// Generates code for an expression that is supposed to return a single value.
|
||||
void visitExpression(solidity::assembly::Statement const& _expression);
|
||||
|
||||
void generateAssignment(solidity::assembly::Identifier const& _variableName, SourceLocation const& _location);
|
||||
void generateAssignment(solidity::assembly::Identifier const& _variableName);
|
||||
|
||||
/// Determines the stack height difference to the given variables. Automatically generates
|
||||
/// errors if it is not yet in scope or the height difference is too large. Returns 0 on
|
||||
/// errors and the (positive) stack height difference otherwise.
|
||||
int variableHeightDiff(solidity::assembly::Scope::Variable const& _var, SourceLocation const& _location, bool _forSwap);
|
||||
/// Determines the stack height difference to the given variables. Throws
|
||||
/// if it is not yet in scope or the height difference is too large. Returns
|
||||
/// the (positive) stack height difference otherwise.
|
||||
int variableHeightDiff(solidity::assembly::Scope::Variable const& _var, bool _forSwap);
|
||||
|
||||
void expectDeposit(int _deposit, int _oldHeight);
|
||||
|
||||
@@ -123,7 +120,6 @@ private:
|
||||
/// Assigns the label's or function's id to a value taken from eth::Assembly if it has not yet been set.
|
||||
void assignLabelIdIfUnset(boost::optional<AbstractAssembly::LabelID>& _labelId);
|
||||
|
||||
solidity::ErrorReporter& m_errorReporter;
|
||||
julia::AbstractAssembly& m_assembly;
|
||||
solidity::assembly::AsmAnalysisInfo& m_info;
|
||||
solidity::assembly::Scope* m_scope = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user