Make Dialect const.

This commit is contained in:
chriseth 2019-05-16 10:24:03 +02:00
parent 9a387380b3
commit 570db164c9
27 changed files with 51 additions and 50 deletions

View File

@ -70,7 +70,7 @@ bool AsmAnalyzer::analyze(Block const& _block)
}
AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(
shared_ptr<Dialect> _dialect,
shared_ptr<Dialect const> _dialect,
Block const& _ast
)
{

View File

@ -60,7 +60,7 @@ public:
AsmAnalysisInfo& _analysisInfo,
langutil::ErrorReporter& _errorReporter,
boost::optional<langutil::Error::Type> _errorTypeForLoose,
std::shared_ptr<Dialect> _dialect,
std::shared_ptr<Dialect const> _dialect,
ExternalIdentifierAccess::Resolver const& _resolver = ExternalIdentifierAccess::Resolver()
):
m_resolver(_resolver),
@ -76,7 +76,7 @@ public:
bool analyze(Block const& _block);
static AsmAnalysisInfo analyzeStrictAssertCorrect(
std::shared_ptr<Dialect> _dialect,
std::shared_ptr<Dialect const> _dialect,
Block const& _ast
);
@ -125,7 +125,7 @@ private:
AsmAnalysisInfo& m_info;
langutil::ErrorReporter& m_errorReporter;
langutil::EVMVersion m_evmVersion;
std::shared_ptr<Dialect> m_dialect;
std::shared_ptr<Dialect const> m_dialect;
boost::optional<langutil::Error::Type> m_errorTypeForLoose;
ForLoop const* m_currentForLoop = nullptr;
};

View File

@ -44,7 +44,7 @@ public:
None, ForLoopPre, ForLoopPost, ForLoopBody
};
explicit Parser(langutil::ErrorReporter& _errorReporter, std::shared_ptr<Dialect> _dialect):
explicit Parser(langutil::ErrorReporter& _errorReporter, std::shared_ptr<Dialect const> _dialect):
ParserBase(_errorReporter), m_dialect(std::move(_dialect)) {}
/// Parses an inline assembly block starting with `{` and ending with `}`.
@ -97,7 +97,7 @@ protected:
static bool isValidNumberLiteral(std::string const& _literal);
private:
std::shared_ptr<Dialect> m_dialect;
std::shared_ptr<Dialect const> m_dialect;
ForLoopComponent m_currentForLoopComponent = ForLoopComponent::None;
};

View File

@ -47,7 +47,7 @@ using namespace yul;
namespace
{
shared_ptr<Dialect> languageToDialect(AssemblyStack::Language _language, EVMVersion _version)
shared_ptr<Dialect const> languageToDialect(AssemblyStack::Language _language, EVMVersion _version)
{
switch (_language)
{
@ -124,7 +124,7 @@ bool AssemblyStack::analyzeParsed(Object& _object)
void AssemblyStack::compileEVM(AbstractAssembly& _assembly, bool _evm15, bool _optimize) const
{
shared_ptr<EVMDialect> dialect;
shared_ptr<EVMDialect const> dialect;
if (m_language == Language::Assembly)
dialect = EVMDialect::looseAssemblyForEVM(m_evmVersion);
@ -184,7 +184,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
case Machine::eWasm:
{
solAssert(m_language == Language::EWasm, "");
shared_ptr<Dialect> dialect = languageToDialect(m_language, EVMVersion{});
shared_ptr<Dialect const> dialect = languageToDialect(m_language, EVMVersion{});
MachineAssemblyObject object;
object.assembly = EWasmObjectCompiler::compile(*m_parserResult, *dialect);

View File

@ -33,7 +33,7 @@ using namespace yul;
using namespace dev;
map<YulString, int> CompilabilityChecker::run(
shared_ptr<Dialect> _dialect,
shared_ptr<Dialect const> _dialect,
Block const& _ast,
bool _optimizeStackAllocation
)
@ -44,7 +44,8 @@ map<YulString, int> CompilabilityChecker::run(
solAssert(_dialect->flavour == AsmFlavour::Strict, "");
solAssert(dynamic_cast<EVMDialect const*>(_dialect.get()), "");
shared_ptr<NoOutputEVMDialect> noOutputDialect = make_shared<NoOutputEVMDialect>(dynamic_pointer_cast<EVMDialect>(_dialect));
shared_ptr<NoOutputEVMDialect const> noOutputDialect =
make_shared<NoOutputEVMDialect>(dynamic_pointer_cast<EVMDialect const>(_dialect));
BuiltinContext builtinContext;
yul::AsmAnalysisInfo analysisInfo =

View File

@ -40,7 +40,7 @@ class CompilabilityChecker
{
public:
static std::map<YulString, int> run(
std::shared_ptr<Dialect> _dialect,
std::shared_ptr<Dialect const> _dialect,
Block const& _ast,
bool _optimizeStackAllocation
);

View File

@ -64,7 +64,7 @@ struct Dialect: boost::noncopyable
Dialect(AsmFlavour _flavour): flavour(_flavour) {}
virtual ~Dialect() = default;
static std::shared_ptr<Dialect> yul()
static std::shared_ptr<Dialect const> yul()
{
// Will have to add builtins later.
return std::make_shared<Dialect>(AsmFlavour::Yul);

View File

@ -47,7 +47,7 @@ class ObjectParser: public langutil::ParserBase
public:
explicit ObjectParser(
langutil::ErrorReporter& _errorReporter,
std::shared_ptr<Dialect> _dialect
std::shared_ptr<Dialect const> _dialect
):
ParserBase(_errorReporter), m_dialect(std::move(_dialect)) {}
@ -67,7 +67,7 @@ private:
YulString parseUniqueName(Object const* _containingObject);
void addNamedSubObject(Object& _container, YulString _name, std::shared_ptr<ObjectNode> _subObject);
std::shared_ptr<Dialect> m_dialect;
std::shared_ptr<Dialect const> m_dialect;
};
}

View File

@ -184,7 +184,7 @@ void CodeGenerator::assemble(
)
{
EthAssemblyAdapter assemblyAdapter(_assembly);
shared_ptr<EVMDialect> dialect = EVMDialect::strictAssemblyForEVM(_evmVersion);
shared_ptr<EVMDialect const> dialect = EVMDialect::strictAssemblyForEVM(_evmVersion);
BuiltinContext builtinContext;
CodeTransform transform(
assemblyAdapter,

View File

@ -138,22 +138,22 @@ BuiltinFunctionForEVM const* EVMDialect::builtin(YulString _name) const
return nullptr;
}
shared_ptr<EVMDialect> EVMDialect::looseAssemblyForEVM(langutil::EVMVersion _version)
shared_ptr<EVMDialect const> EVMDialect::looseAssemblyForEVM(langutil::EVMVersion _version)
{
return make_shared<EVMDialect>(AsmFlavour::Loose, false, _version);
}
shared_ptr<EVMDialect> EVMDialect::strictAssemblyForEVM(langutil::EVMVersion _version)
shared_ptr<EVMDialect const> EVMDialect::strictAssemblyForEVM(langutil::EVMVersion _version)
{
return make_shared<EVMDialect>(AsmFlavour::Strict, false, _version);
}
shared_ptr<EVMDialect> EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion _version)
shared_ptr<EVMDialect const> EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion _version)
{
return make_shared<EVMDialect>(AsmFlavour::Strict, true, _version);
}
shared_ptr<yul::EVMDialect> EVMDialect::yulForEVM(langutil::EVMVersion _version)
shared_ptr<EVMDialect const> EVMDialect::yulForEVM(langutil::EVMVersion _version)
{
return make_shared<EVMDialect>(AsmFlavour::Yul, false, _version);
}

View File

@ -66,10 +66,10 @@ struct EVMDialect: public Dialect
/// @returns the builtin function of the given name or a nullptr if it is not a builtin function.
BuiltinFunctionForEVM const* builtin(YulString _name) const override;
static std::shared_ptr<EVMDialect> looseAssemblyForEVM(langutil::EVMVersion _version);
static std::shared_ptr<EVMDialect> strictAssemblyForEVM(langutil::EVMVersion _version);
static std::shared_ptr<EVMDialect> strictAssemblyForEVMObjects(langutil::EVMVersion _version);
static std::shared_ptr<EVMDialect> yulForEVM(langutil::EVMVersion _version);
static std::shared_ptr<EVMDialect const> looseAssemblyForEVM(langutil::EVMVersion _version);
static std::shared_ptr<EVMDialect const> strictAssemblyForEVM(langutil::EVMVersion _version);
static std::shared_ptr<EVMDialect const> strictAssemblyForEVMObjects(langutil::EVMVersion _version);
static std::shared_ptr<EVMDialect const> yulForEVM(langutil::EVMVersion _version);
langutil::EVMVersion evmVersion() const { return m_evmVersion; }

View File

@ -29,7 +29,7 @@
using namespace yul;
using namespace std;
void EVMObjectCompiler::compile(Object& _object, AbstractAssembly& _assembly, EVMDialect& _dialect, bool _evm15, bool _optimize)
void EVMObjectCompiler::compile(Object& _object, AbstractAssembly& _assembly, EVMDialect const& _dialect, bool _evm15, bool _optimize)
{
EVMObjectCompiler compiler(_assembly, _dialect, _evm15);
compiler.run(_object, _optimize);

View File

@ -29,16 +29,16 @@ struct EVMDialect;
class EVMObjectCompiler
{
public:
static void compile(Object& _object, AbstractAssembly& _assembly, EVMDialect& _dialect, bool _evm15, bool _optimize);
static void compile(Object& _object, AbstractAssembly& _assembly, EVMDialect const& _dialect, bool _evm15, bool _optimize);
private:
EVMObjectCompiler(AbstractAssembly& _assembly, EVMDialect& _dialect, bool _evm15):
EVMObjectCompiler(AbstractAssembly& _assembly, EVMDialect const& _dialect, bool _evm15):
m_assembly(_assembly), m_dialect(_dialect), m_evm15(_evm15)
{}
void run(Object& _object, bool _optimize);
AbstractAssembly& m_assembly;
EVMDialect& m_dialect;
EVMDialect const& m_dialect;
bool m_evm15 = false;
};

View File

@ -142,7 +142,7 @@ AbstractAssembly::SubID NoOutputAssembly::appendData(bytes const&)
return 1;
}
NoOutputEVMDialect::NoOutputEVMDialect(shared_ptr<EVMDialect> const& _copyFrom):
NoOutputEVMDialect::NoOutputEVMDialect(shared_ptr<EVMDialect const> const& _copyFrom):
EVMDialect(_copyFrom->flavour, _copyFrom->providesObjectAccess(), _copyFrom->evmVersion())
{
for (auto& fun: m_functions)

View File

@ -81,7 +81,7 @@ private:
*/
struct NoOutputEVMDialect: public EVMDialect
{
explicit NoOutputEVMDialect(std::shared_ptr<EVMDialect> const& _copyFrom);
explicit NoOutputEVMDialect(std::shared_ptr<EVMDialect const> const& _copyFrom);
};

View File

@ -28,7 +28,7 @@
using namespace yul;
using namespace std;
string EWasmObjectCompiler::compile(Object& _object, Dialect& _dialect)
string EWasmObjectCompiler::compile(Object& _object, Dialect const& _dialect)
{
EWasmObjectCompiler compiler(_dialect);
return compiler.run(_object);

View File

@ -30,15 +30,15 @@ struct Dialect;
class EWasmObjectCompiler
{
public:
static std::string compile(Object& _object, Dialect& _dialect);
static std::string compile(Object& _object, Dialect const& _dialect);
private:
EWasmObjectCompiler(Dialect& _dialect):
EWasmObjectCompiler(Dialect const& _dialect):
m_dialect(_dialect)
{}
std::string run(Object& _object);
Dialect& m_dialect;
Dialect const& m_dialect;
};
}

View File

@ -112,7 +112,7 @@ public:
};
template <typename ASTNode>
void eliminateVariables(shared_ptr<Dialect> const& _dialect, ASTNode& _node, size_t _numVariables)
void eliminateVariables(shared_ptr<Dialect const> const& _dialect, ASTNode& _node, size_t _numVariables)
{
RematCandidateSelector selector{*_dialect};
selector(_node);
@ -133,7 +133,7 @@ void eliminateVariables(shared_ptr<Dialect> const& _dialect, ASTNode& _node, siz
}
bool StackCompressor::run(
shared_ptr<Dialect> const& _dialect,
shared_ptr<Dialect const> const& _dialect,
Block& _ast,
bool _optimizeStackAllocation,
size_t _maxIterations

View File

@ -42,7 +42,7 @@ public:
/// Try to remove local variables until the AST is compilable.
/// @returns true if it was successful.
static bool run(
std::shared_ptr<Dialect> const& _dialect,
std::shared_ptr<Dialect const> const& _dialect,
Block& _ast,
bool _optimizeStackAllocation,
size_t _maxIterations

View File

@ -58,7 +58,7 @@ using namespace dev;
using namespace yul;
void OptimiserSuite::run(
shared_ptr<Dialect> const& _dialect,
shared_ptr<Dialect const> const& _dialect,
Block& _ast,
AsmAnalysisInfo const& _analysisInfo,
bool _optimizeStackAllocation,

View File

@ -39,7 +39,7 @@ class OptimiserSuite
{
public:
static void run(
std::shared_ptr<Dialect> const& _dialect,
std::shared_ptr<Dialect const> const& _dialect,
Block& _ast,
AsmAnalysisInfo const& _analysisInfo,
bool _optimizeStackAllocation,

View File

@ -43,7 +43,7 @@ using namespace yul;
namespace
{
shared_ptr<Dialect> defaultDialect(bool _yul)
shared_ptr<Dialect const> defaultDialect(bool _yul)
{
return _yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVM(dev::test::Options::get().evmVersion());
}

View File

@ -49,7 +49,7 @@ namespace test
namespace
{
bool parse(string const& _source, std::shared_ptr<Dialect> _dialect, ErrorReporter& errorReporter)
bool parse(string const& _source, std::shared_ptr<Dialect const> _dialect, ErrorReporter& errorReporter)
{
try
{
@ -73,7 +73,7 @@ bool parse(string const& _source, std::shared_ptr<Dialect> _dialect, ErrorReport
return false;
}
boost::optional<Error> parseAndReturnFirstError(string const& _source, shared_ptr<Dialect> _dialect, bool _allowWarnings = true)
boost::optional<Error> parseAndReturnFirstError(string const& _source, shared_ptr<Dialect const> _dialect, bool _allowWarnings = true)
{
ErrorList errors;
ErrorReporter errorReporter(errors);
@ -98,12 +98,12 @@ boost::optional<Error> parseAndReturnFirstError(string const& _source, shared_pt
return {};
}
bool successParse(std::string const& _source, shared_ptr<Dialect> _dialect = Dialect::yul(), bool _allowWarnings = true)
bool successParse(std::string const& _source, shared_ptr<Dialect const> _dialect = Dialect::yul(), bool _allowWarnings = true)
{
return !parseAndReturnFirstError(_source, _dialect, _allowWarnings);
}
Error expectError(std::string const& _source, shared_ptr<Dialect> _dialect = Dialect::yul(), bool _allowWarnings = false)
Error expectError(std::string const& _source, shared_ptr<Dialect const> _dialect = Dialect::yul(), bool _allowWarnings = false)
{
auto error = parseAndReturnFirstError(_source, _dialect, _allowWarnings);
@ -548,7 +548,7 @@ BOOST_AUTO_TEST_CASE(builtins_parser)
BuiltinFunction f;
};
shared_ptr<Dialect> dialect = make_shared<SimpleDialect>();
shared_ptr<Dialect const> dialect = make_shared<SimpleDialect>();
CHECK_ERROR_DIALECT("{ let builtin := 6 }", ParserError, "Cannot use builtin function name \"builtin\" as identifier name.", dialect);
CHECK_ERROR_DIALECT("{ function builtin() {} }", ParserError, "Cannot use builtin function name \"builtin\" as identifier name.", dialect);
CHECK_ERROR_DIALECT("{ builtin := 6 }", ParserError, "Cannot assign to builtin function \"builtin\".", dialect);
@ -567,7 +567,7 @@ BOOST_AUTO_TEST_CASE(builtins_analysis)
BuiltinFunction f{"builtin"_yulstring, vector<Type>(2), vector<Type>(3), false, false};
};
shared_ptr<Dialect> dialect = make_shared<SimpleDialect>();
shared_ptr<Dialect const> dialect = make_shared<SimpleDialect>();
BOOST_CHECK(successParse("{ let a, b, c := builtin(1, 2) }", dialect));
CHECK_ERROR_DIALECT("{ let a, b, c := builtin(1) }", TypeError, "Function expects 2 arguments but got 1", dialect);
CHECK_ERROR_DIALECT("{ let a, b := builtin(1, 2) }", DeclarationError, "Variable count mismatch: 2 variables and 3 values.", dialect);

View File

@ -132,7 +132,7 @@ string YulInterpreterTest::interpret()
state.maxTraceSize = 10000;
state.maxSteps = 10000;
state.maxMemSize = 0x20000000;
shared_ptr<Dialect> dialect(EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion{}));
shared_ptr<Dialect const> dialect(EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion{}));
Interpreter interpreter(state, *dialect);
try
{

View File

@ -66,7 +66,7 @@ private:
std::string m_optimizerStep;
std::string m_expectation;
std::shared_ptr<Dialect> m_dialect;
std::shared_ptr<Dialect const> m_dialect;
std::shared_ptr<Block> m_ast;
std::shared_ptr<AsmAnalysisInfo> m_analysisInfo;
std::string m_obtainedResult;

View File

@ -215,7 +215,7 @@ public:
private:
ErrorList m_errors;
shared_ptr<yul::Block> m_ast;
shared_ptr<Dialect> m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion{})};
shared_ptr<Dialect const> m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion{})};
shared_ptr<AsmAnalysisInfo> m_analysisInfo;
shared_ptr<NameDispenser> m_nameDispenser;
};

View File

@ -88,7 +88,7 @@ void interpret(string const& _source)
InterpreterState state;
state.maxTraceSize = 10000;
state.maxMemSize = 0x20000000;
shared_ptr<Dialect> dialect(EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion{}));
shared_ptr<Dialect const> dialect(EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion{}));
Interpreter interpreter(state, *dialect);
try
{