mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move "active variable" to analysis phase.
This commit is contained in:
parent
1bf717fd65
commit
154002cda0
@ -91,7 +91,7 @@ bool AsmAnalyzer::operator()(assembly::Identifier const& _identifier)
|
|||||||
if (m_currentScope->lookup(_identifier.name, Scope::Visitor(
|
if (m_currentScope->lookup(_identifier.name, Scope::Visitor(
|
||||||
[&](Scope::Variable const& _var)
|
[&](Scope::Variable const& _var)
|
||||||
{
|
{
|
||||||
if (!_var.active)
|
if (!m_activeVariables.count(&_var))
|
||||||
{
|
{
|
||||||
m_errorReporter.declarationError(
|
m_errorReporter.declarationError(
|
||||||
_identifier.location,
|
_identifier.location,
|
||||||
@ -185,7 +185,7 @@ bool AsmAnalyzer::operator()(assembly::VariableDeclaration const& _varDecl)
|
|||||||
for (auto const& variable: _varDecl.variables)
|
for (auto const& variable: _varDecl.variables)
|
||||||
{
|
{
|
||||||
expectValidType(variable.type, variable.location);
|
expectValidType(variable.type, variable.location);
|
||||||
boost::get<Scope::Variable>(m_currentScope->identifiers.at(variable.name)).active = true;
|
m_activeVariables.insert(&boost::get<Scope::Variable>(m_currentScope->identifiers.at(variable.name)));
|
||||||
}
|
}
|
||||||
m_info.stackHeightInfo[&_varDecl] = m_stackHeight;
|
m_info.stackHeightInfo[&_varDecl] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
@ -199,7 +199,7 @@ bool AsmAnalyzer::operator()(assembly::FunctionDefinition const& _funDef)
|
|||||||
for (auto const& var: _funDef.arguments + _funDef.returns)
|
for (auto const& var: _funDef.arguments + _funDef.returns)
|
||||||
{
|
{
|
||||||
expectValidType(var.type, var.location);
|
expectValidType(var.type, var.location);
|
||||||
boost::get<Scope::Variable>(varScope.identifiers.at(var.name)).active = true;
|
m_activeVariables.insert(&boost::get<Scope::Variable>(varScope.identifiers.at(var.name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
int const stackHeight = m_stackHeight;
|
int const stackHeight = m_stackHeight;
|
||||||
@ -382,7 +382,7 @@ bool AsmAnalyzer::checkAssignment(assembly::Identifier const& _variable, size_t
|
|||||||
m_errorReporter.typeError(_variable.location, "Assignment requires variable.");
|
m_errorReporter.typeError(_variable.location, "Assignment requires variable.");
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
else if (!boost::get<Scope::Variable>(*var).active)
|
else if (!m_activeVariables.count(&boost::get<Scope::Variable>(*var)))
|
||||||
{
|
{
|
||||||
m_errorReporter.declarationError(
|
m_errorReporter.declarationError(
|
||||||
_variable.location,
|
_variable.location,
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <libsolidity/interface/Exceptions.h>
|
#include <libsolidity/interface/Exceptions.h>
|
||||||
|
|
||||||
|
#include <libsolidity/inlineasm/AsmScope.h>
|
||||||
|
|
||||||
#include <libjulia/backends/evm/AbstractAssembly.h>
|
#include <libjulia/backends/evm/AbstractAssembly.h>
|
||||||
|
|
||||||
#include <boost/variant.hpp>
|
#include <boost/variant.hpp>
|
||||||
@ -51,9 +53,6 @@ struct FunctionCall;
|
|||||||
struct Switch;
|
struct Switch;
|
||||||
using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Switch, Block>;
|
using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Switch, Block>;
|
||||||
|
|
||||||
|
|
||||||
struct Scope;
|
|
||||||
|
|
||||||
struct AsmAnalysisInfo;
|
struct AsmAnalysisInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,6 +100,9 @@ private:
|
|||||||
int m_stackHeight = 0;
|
int m_stackHeight = 0;
|
||||||
julia::ExternalIdentifierAccess::Resolver m_resolver;
|
julia::ExternalIdentifierAccess::Resolver m_resolver;
|
||||||
Scope* m_currentScope = nullptr;
|
Scope* m_currentScope = nullptr;
|
||||||
|
/// Variables that are active at the current point in assembly (as opposed to
|
||||||
|
/// "part of the scope but not yet declared")
|
||||||
|
std::set<Scope::Variable const*> m_activeVariables;
|
||||||
AsmAnalysisInfo& m_info;
|
AsmAnalysisInfo& m_info;
|
||||||
ErrorReporter& m_errorReporter;
|
ErrorReporter& m_errorReporter;
|
||||||
bool m_julia = false;
|
bool m_julia = false;
|
||||||
|
@ -65,16 +65,8 @@ struct Scope
|
|||||||
using JuliaType = std::string;
|
using JuliaType = std::string;
|
||||||
using LabelID = size_t;
|
using LabelID = size_t;
|
||||||
|
|
||||||
struct Variable
|
struct Variable { JuliaType type; };
|
||||||
{
|
|
||||||
/// Used during analysis to check whether we already passed the declaration inside the block.
|
|
||||||
/// @todo move there.
|
|
||||||
bool active = false;
|
|
||||||
JuliaType type;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Label { };
|
struct Label { };
|
||||||
|
|
||||||
struct Function
|
struct Function
|
||||||
{
|
{
|
||||||
std::vector<JuliaType> arguments;
|
std::vector<JuliaType> arguments;
|
||||||
|
Loading…
Reference in New Issue
Block a user