aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorChristian Parpart <christian@ethereum.org>2018-11-21 19:42:34 +0800
committerChristian Parpart <christian@ethereum.org>2018-11-23 21:29:00 +0800
commitec47c8946ba5f78563b7eca2512b3cee68db45b4 (patch)
tree58216cdbf00dba9a61135d85b289ce2af9fc2974 /libsolidity
parent3734f40d315439f8a791967a6adfda8cf9fd1e55 (diff)
downloaddexon-solidity-ec47c8946ba5f78563b7eca2512b3cee68db45b4.tar.gz
dexon-solidity-ec47c8946ba5f78563b7eca2512b3cee68db45b4.tar.zst
dexon-solidity-ec47c8946ba5f78563b7eca2512b3cee68db45b4.zip
Isolating libyul library API into its own namespace `yul`.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/ReferencesResolver.cpp6
-rw-r--r--libsolidity/analysis/TypeChecker.cpp8
-rw-r--r--libsolidity/analysis/ViewPureChecker.cpp30
-rw-r--r--libsolidity/ast/AST.h18
-rw-r--r--libsolidity/ast/ASTAnnotations.h16
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp4
-rw-r--r--libsolidity/ast/ASTJsonConverter.h2
-rw-r--r--libsolidity/codegen/CompilerContext.cpp16
-rw-r--r--libsolidity/codegen/ContractCompiler.cpp6
-rw-r--r--libsolidity/interface/AssemblyStack.cpp24
-rw-r--r--libsolidity/interface/AssemblyStack.h17
-rw-r--r--libsolidity/parsing/Parser.cpp4
12 files changed, 76 insertions, 75 deletions
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp
index 1593c3e0..c4931d98 100644
--- a/libsolidity/analysis/ReferencesResolver.cpp
+++ b/libsolidity/analysis/ReferencesResolver.cpp
@@ -273,7 +273,7 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
ErrorList errors;
ErrorReporter errorsIgnored(errors);
yul::ExternalIdentifierAccess::Resolver resolver =
- [&](assembly::Identifier const& _identifier, yul::IdentifierContext, bool _crossesFunctionBoundary) {
+ [&](yul::Identifier const& _identifier, yul::IdentifierContext, bool _crossesFunctionBoundary) {
auto declarations = m_resolver.nameFromCurrentScope(_identifier.name.str());
bool isSlot = boost::algorithm::ends_with(_identifier.name.str(), "_slot");
bool isOffset = boost::algorithm::ends_with(_identifier.name.str(), "_offset");
@@ -314,9 +314,9 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
// Will be re-generated later with correct information
// We use the latest EVM version because we will re-run it anyway.
- assembly::AsmAnalysisInfo analysisInfo;
+ yul::AsmAnalysisInfo analysisInfo;
boost::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError;
- assembly::AsmAnalyzer(analysisInfo, errorsIgnored, EVMVersion(), errorTypeForLoose, assembly::AsmFlavour::Loose, resolver).analyze(_inlineAssembly.operations());
+ yul::AsmAnalyzer(analysisInfo, errorsIgnored, EVMVersion(), errorTypeForLoose, yul::AsmFlavour::Loose, resolver).analyze(_inlineAssembly.operations());
return false;
}
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 3cf4d79f..4e63875b 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -954,7 +954,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
// External references have already been resolved in a prior stage and stored in the annotation.
// We run the resolve step again regardless.
yul::ExternalIdentifierAccess::Resolver identifierAccess = [&](
- assembly::Identifier const& _identifier,
+ yul::Identifier const& _identifier,
yul::IdentifierContext _context,
bool
)
@@ -1039,13 +1039,13 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
return size_t(1);
};
solAssert(!_inlineAssembly.annotation().analysisInfo, "");
- _inlineAssembly.annotation().analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
- assembly::AsmAnalyzer analyzer(
+ _inlineAssembly.annotation().analysisInfo = make_shared<yul::AsmAnalysisInfo>();
+ yul::AsmAnalyzer analyzer(
*_inlineAssembly.annotation().analysisInfo,
m_errorReporter,
m_evmVersion,
Error::Type::SyntaxError,
- assembly::AsmFlavour::Loose,
+ yul::AsmFlavour::Loose,
identifierAccess
);
if (!analyzer.analyze(_inlineAssembly.operations()))
diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp
index 7839ecd3..1112d682 100644
--- a/libsolidity/analysis/ViewPureChecker.cpp
+++ b/libsolidity/analysis/ViewPureChecker.cpp
@@ -40,48 +40,48 @@ public:
explicit AssemblyViewPureChecker(std::function<void(StateMutability, SourceLocation const&)> _reportMutability):
m_reportMutability(_reportMutability) {}
- void operator()(assembly::Label const&) { }
- void operator()(assembly::Instruction const& _instruction)
+ void operator()(yul::Label const&) { }
+ void operator()(yul::Instruction const& _instruction)
{
checkInstruction(_instruction.location, _instruction.instruction);
}
- void operator()(assembly::Literal const&) {}
- void operator()(assembly::Identifier const&) {}
- void operator()(assembly::FunctionalInstruction const& _instr)
+ void operator()(yul::Literal const&) {}
+ void operator()(yul::Identifier const&) {}
+ void operator()(yul::FunctionalInstruction const& _instr)
{
checkInstruction(_instr.location, _instr.instruction);
for (auto const& arg: _instr.arguments)
boost::apply_visitor(*this, arg);
}
- void operator()(assembly::ExpressionStatement const& _expr)
+ void operator()(yul::ExpressionStatement const& _expr)
{
boost::apply_visitor(*this, _expr.expression);
}
- void operator()(assembly::StackAssignment const&) {}
- void operator()(assembly::Assignment const& _assignment)
+ void operator()(yul::StackAssignment const&) {}
+ void operator()(yul::Assignment const& _assignment)
{
boost::apply_visitor(*this, *_assignment.value);
}
- void operator()(assembly::VariableDeclaration const& _varDecl)
+ void operator()(yul::VariableDeclaration const& _varDecl)
{
if (_varDecl.value)
boost::apply_visitor(*this, *_varDecl.value);
}
- void operator()(assembly::FunctionDefinition const& _funDef)
+ void operator()(yul::FunctionDefinition const& _funDef)
{
(*this)(_funDef.body);
}
- void operator()(assembly::FunctionCall const& _funCall)
+ void operator()(yul::FunctionCall const& _funCall)
{
for (auto const& arg: _funCall.arguments)
boost::apply_visitor(*this, arg);
}
- void operator()(assembly::If const& _if)
+ void operator()(yul::If const& _if)
{
boost::apply_visitor(*this, *_if.condition);
(*this)(_if.body);
}
- void operator()(assembly::Switch const& _switch)
+ void operator()(yul::Switch const& _switch)
{
boost::apply_visitor(*this, *_switch.expression);
for (auto const& _case: _switch.cases)
@@ -91,14 +91,14 @@ public:
(*this)(_case.body);
}
}
- void operator()(assembly::ForLoop const& _for)
+ void operator()(yul::ForLoop const& _for)
{
(*this)(_for.pre);
boost::apply_visitor(*this, *_for.condition);
(*this)(_for.body);
(*this)(_for.post);
}
- void operator()(assembly::Block const& _block)
+ void operator()(yul::Block const& _block)
{
for (auto const& s: _block.statements)
boost::apply_visitor(*this, s);
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index d23562ad..2f418b09 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -41,6 +41,12 @@
#include <vector>
#include <memory>
+namespace yul
+{
+// Forward-declaration to <yul/AsmData.h>
+struct Block;
+}
+
namespace dev
{
namespace solidity
@@ -1028,12 +1034,6 @@ public:
StatementAnnotation& annotation() const override;
};
-namespace assembly
-{
-// Forward-declaration to AsmData.h
-struct Block;
-}
-
/**
* Inline assembly.
*/
@@ -1043,18 +1043,18 @@ public:
InlineAssembly(
SourceLocation const& _location,
ASTPointer<ASTString> const& _docString,
- std::shared_ptr<assembly::Block> const& _operations
+ std::shared_ptr<yul::Block> const& _operations
):
Statement(_location, _docString), m_operations(_operations) {}
void accept(ASTVisitor& _visitor) override;
void accept(ASTConstVisitor& _visitor) const override;
- assembly::Block const& operations() const { return *m_operations; }
+ yul::Block const& operations() const { return *m_operations; }
InlineAssemblyAnnotation& annotation() const override;
private:
- std::shared_ptr<assembly::Block> m_operations;
+ std::shared_ptr<yul::Block> m_operations;
};
/**
diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h
index e0b3f492..e9cc905e 100644
--- a/libsolidity/ast/ASTAnnotations.h
+++ b/libsolidity/ast/ASTAnnotations.h
@@ -30,6 +30,12 @@
#include <vector>
#include <set>
+namespace yul
+{
+ struct AsmAnalysisInfo;
+ struct Identifier;
+}
+
namespace dev
{
namespace solidity
@@ -120,12 +126,6 @@ struct StatementAnnotation: ASTAnnotation, DocumentedAnnotation
{
};
-namespace assembly
-{
- struct AsmAnalysisInfo;
- struct Identifier;
-}
-
struct InlineAssemblyAnnotation: StatementAnnotation
{
struct ExternalIdentifierInfo
@@ -137,9 +137,9 @@ struct InlineAssemblyAnnotation: StatementAnnotation
};
/// Mapping containing resolved references to external identifiers and their value size
- std::map<assembly::Identifier const*, ExternalIdentifierInfo> externalReferences;
+ std::map<yul::Identifier const*, ExternalIdentifierInfo> externalReferences;
/// Information generated during analysis phase.
- std::shared_ptr<assembly::AsmAnalysisInfo> analysisInfo;
+ std::shared_ptr<yul::AsmAnalysisInfo> analysisInfo;
};
struct ReturnAnnotation: StatementAnnotation
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index bd6deb6e..b9054692 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -172,7 +172,7 @@ void ASTJsonConverter::appendExpressionAttributes(
_attributes += exprAttributes;
}
-Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair<assembly::Identifier const* ,InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const
+Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair<yul::Identifier const* ,InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const
{
Json::Value tuple(Json::objectValue);
tuple["src"] = sourceLocationToString(_info.first->location);
@@ -465,7 +465,7 @@ bool ASTJsonConverter::visit(InlineAssembly const& _node)
}
}
setJsonNode(_node, "InlineAssembly", {
- make_pair("operations", Json::Value(assembly::AsmPrinter()(_node.operations()))),
+ make_pair("operations", Json::Value(yul::AsmPrinter()(_node.operations()))),
make_pair("externalReferences", std::move(externalReferences))
});
return false;
diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h
index dec3ac96..ef0a217a 100644
--- a/libsolidity/ast/ASTJsonConverter.h
+++ b/libsolidity/ast/ASTJsonConverter.h
@@ -135,7 +135,7 @@ private:
{
return _node ? toJson(*_node) : Json::nullValue;
}
- Json::Value inlineAssemblyIdentifierToJson(std::pair<assembly::Identifier const* , InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const;
+ Json::Value inlineAssemblyIdentifierToJson(std::pair<yul::Identifier const* , InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const;
static std::string location(VariableDeclaration::Location _location);
static std::string contractKind(ContractDefinition::ContractKind _kind);
static std::string functionCallKind(FunctionCallKind _kind);
diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp
index 32be521c..d1bf29fc 100644
--- a/libsolidity/codegen/CompilerContext.cpp
+++ b/libsolidity/codegen/CompilerContext.cpp
@@ -323,7 +323,7 @@ void CompilerContext::appendInlineAssembly(
yul::ExternalIdentifierAccess identifierAccess;
identifierAccess.resolve = [&](
- assembly::Identifier const& _identifier,
+ yul::Identifier const& _identifier,
yul::IdentifierContext,
bool
)
@@ -332,7 +332,7 @@ void CompilerContext::appendInlineAssembly(
return it == _localVariables.end() ? size_t(-1) : 1;
};
identifierAccess.generateCode = [&](
- assembly::Identifier const& _identifier,
+ yul::Identifier const& _identifier,
yul::IdentifierContext _context,
yul::AbstractAssembly& _assembly
)
@@ -361,19 +361,19 @@ void CompilerContext::appendInlineAssembly(
ErrorList errors;
ErrorReporter errorReporter(errors);
auto scanner = make_shared<langutil::Scanner>(langutil::CharStream(_assembly), "--CODEGEN--");
- auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner, false);
+ auto parserResult = yul::Parser(errorReporter, yul::AsmFlavour::Strict).parse(scanner, false);
#ifdef SOL_OUTPUT_ASM
- cout << assembly::AsmPrinter()(*parserResult) << endl;
+ cout << yul::AsmPrinter()(*parserResult) << endl;
#endif
- assembly::AsmAnalysisInfo analysisInfo;
+ yul::AsmAnalysisInfo analysisInfo;
bool analyzerResult = false;
if (parserResult)
- analyzerResult = assembly::AsmAnalyzer(
+ analyzerResult = yul::AsmAnalyzer(
analysisInfo,
errorReporter,
m_evmVersion,
boost::none,
- assembly::AsmFlavour::Strict,
+ yul::AsmFlavour::Strict,
identifierAccess.resolve
).analyze(*parserResult);
if (!parserResult || !errorReporter.errors().empty() || !analyzerResult)
@@ -395,7 +395,7 @@ void CompilerContext::appendInlineAssembly(
}
solAssert(errorReporter.errors().empty(), "Failed to analyze inline assembly block.");
- assembly::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system);
+ yul::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system);
// Reset the source location to the one of the node (instead of the CODEGEN source location)
updateSourceLocation();
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp
index 815c2a4f..157d5fa7 100644
--- a/libsolidity/codegen/ContractCompiler.cpp
+++ b/libsolidity/codegen/ContractCompiler.cpp
@@ -496,14 +496,14 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
{
unsigned startStackHeight = m_context.stackHeight();
yul::ExternalIdentifierAccess identifierAccess;
- identifierAccess.resolve = [&](assembly::Identifier const& _identifier, yul::IdentifierContext, bool)
+ identifierAccess.resolve = [&](yul::Identifier const& _identifier, yul::IdentifierContext, bool)
{
auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier);
if (ref == _inlineAssembly.annotation().externalReferences.end())
return size_t(-1);
return ref->second.valueSize;
};
- identifierAccess.generateCode = [&](assembly::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly)
+ identifierAccess.generateCode = [&](yul::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly)
{
auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier);
solAssert(ref != _inlineAssembly.annotation().externalReferences.end(), "");
@@ -615,7 +615,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
}
};
solAssert(_inlineAssembly.annotation().analysisInfo, "");
- assembly::CodeGenerator::assemble(
+ yul::CodeGenerator::assemble(
_inlineAssembly.operations(),
*_inlineAssembly.annotation().analysisInfo,
m_context.nonConstAssembly(),
diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp
index cd8b125e..31959d93 100644
--- a/libsolidity/interface/AssemblyStack.cpp
+++ b/libsolidity/interface/AssemblyStack.cpp
@@ -40,19 +40,19 @@ using namespace dev::solidity;
namespace
{
-assembly::AsmFlavour languageToAsmFlavour(AssemblyStack::Language _language)
+yul::AsmFlavour languageToAsmFlavour(AssemblyStack::Language _language)
{
switch (_language)
{
case AssemblyStack::Language::Assembly:
- return assembly::AsmFlavour::Loose;
+ return yul::AsmFlavour::Loose;
case AssemblyStack::Language::StrictAssembly:
- return assembly::AsmFlavour::Strict;
+ return yul::AsmFlavour::Strict;
case AssemblyStack::Language::Yul:
- return assembly::AsmFlavour::Yul;
+ return yul::AsmFlavour::Yul;
}
solAssert(false, "");
- return assembly::AsmFlavour::Yul;
+ return yul::AsmFlavour::Yul;
}
}
@@ -69,7 +69,7 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
m_errors.clear();
m_analysisSuccessful = false;
m_scanner = make_shared<Scanner>(CharStream(_source), _sourceName);
- m_parserResult = assembly::Parser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false);
+ m_parserResult = yul::Parser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false);
if (!m_errorReporter.errors().empty())
return false;
solAssert(m_parserResult, "");
@@ -77,21 +77,21 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
return analyzeParsed();
}
-bool AssemblyStack::analyze(assembly::Block const& _block, Scanner const* _scanner)
+bool AssemblyStack::analyze(yul::Block const& _block, Scanner const* _scanner)
{
m_errors.clear();
m_analysisSuccessful = false;
if (_scanner)
m_scanner = make_shared<Scanner>(*_scanner);
- m_parserResult = make_shared<assembly::Block>(_block);
+ m_parserResult = make_shared<yul::Block>(_block);
return analyzeParsed();
}
bool AssemblyStack::analyzeParsed()
{
- m_analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
- assembly::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter, m_evmVersion, boost::none, languageToAsmFlavour(m_language));
+ m_analysisInfo = make_shared<yul::AsmAnalysisInfo>();
+ yul::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter, m_evmVersion, boost::none, languageToAsmFlavour(m_language));
m_analysisSuccessful = analyzer.analyze(*m_parserResult);
return m_analysisSuccessful;
}
@@ -108,7 +108,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
{
MachineAssemblyObject object;
eth::Assembly assembly;
- assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
+ yul::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
object.bytecode = make_shared<eth::LinkerObject>(assembly.assemble());
object.assembly = assembly.assemblyString();
return object;
@@ -132,5 +132,5 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
string AssemblyStack::print() const
{
solAssert(m_parserResult, "");
- return assembly::AsmPrinter(m_language == Language::Yul)(*m_parserResult);
+ return yul::AsmPrinter(m_language == Language::Yul)(*m_parserResult);
}
diff --git a/libsolidity/interface/AssemblyStack.h b/libsolidity/interface/AssemblyStack.h
index d6ee33cf..03b811db 100644
--- a/libsolidity/interface/AssemblyStack.h
+++ b/libsolidity/interface/AssemblyStack.h
@@ -34,16 +34,17 @@ namespace langutil
class Scanner;
}
-namespace dev
-{
-namespace solidity
-{
-namespace assembly
+namespace yul
{
struct AsmAnalysisInfo;
struct Block;
}
+namespace dev
+{
+namespace solidity
+{
+
struct MachineAssemblyObject
{
std::shared_ptr<eth::LinkerObject> bytecode;
@@ -73,7 +74,7 @@ public:
/// Runs analysis step on the supplied block, returns false if input cannot be assembled.
/// Multiple calls overwrite the previous state.
- bool analyze(assembly::Block const& _block, langutil::Scanner const* _scanner = nullptr);
+ bool analyze(yul::Block const& _block, langutil::Scanner const* _scanner = nullptr);
/// Run the assembly step (should only be called after parseAndAnalyze).
MachineAssemblyObject assemble(Machine _machine) const;
@@ -93,8 +94,8 @@ private:
std::shared_ptr<langutil::Scanner> m_scanner;
bool m_analysisSuccessful = false;
- std::shared_ptr<assembly::Block> m_parserResult;
- std::shared_ptr<assembly::AsmAnalysisInfo> m_analysisInfo;
+ std::shared_ptr<yul::Block> m_parserResult;
+ std::shared_ptr<yul::AsmAnalysisInfo> m_analysisInfo;
langutil::ErrorList m_errors;
langutil::ErrorReporter m_errorReporter;
};
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index 560d8e8b..ffe2be83 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -1012,8 +1012,8 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
m_scanner->next();
}
- assembly::Parser asmParser(m_errorReporter);
- shared_ptr<assembly::Block> block = asmParser.parse(m_scanner, true);
+ yul::Parser asmParser(m_errorReporter);
+ shared_ptr<yul::Block> block = asmParser.parse(m_scanner, true);
nodeFactory.markEndPosition();
return nodeFactory.createNode<InlineAssembly>(_docString, block);
}