C++ namespace cleanup (except tests).

This commit is contained in:
Christian Parpart
2020-01-07 15:51:50 +01:00
committed by Daniel Kirchner
parent 8385256bdc
commit 6b23412fae
403 changed files with 1656 additions and 1926 deletions
+2 -2
View File
@@ -27,8 +27,8 @@
#include <liblangutil/ErrorReporter.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
{
+2 -5
View File
@@ -24,14 +24,12 @@
#include <libsolidity/ast/ASTVisitor.h>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class TypeChecker;
@@ -72,4 +70,3 @@ private:
};
}
}
@@ -30,9 +30,9 @@
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
namespace
{
@@ -361,10 +361,10 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contract)
{
set<FixedHash<4>> hashes;
set<util::FixedHash<4>> hashes;
for (auto const& it: _contract.interfaceFunctionList())
{
FixedHash<4> const& hash = it.first;
util::FixedHash<4> const& hash = it.first;
if (hashes.count(hash))
m_errorReporter.typeError(
_contract.location(),
+2 -5
View File
@@ -28,14 +28,12 @@
#include <functional>
#include <set>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -90,4 +88,3 @@ private:
};
}
}
+4 -4
View File
@@ -22,8 +22,8 @@
#include <boost/range/algorithm/sort.hpp>
using namespace std;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
bool ControlFlowAnalyzer::analyze(ASTNode const& _astRoot)
{
@@ -151,7 +151,7 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod
void ControlFlowAnalyzer::checkUnreachable(CFGNode const* _entry, CFGNode const* _exit, CFGNode const* _revert) const
{
// collect all nodes reachable from the entry point
std::set<CFGNode const*> reachable = BreadthFirstSearch<CFGNode const*>{{_entry}}.run(
std::set<CFGNode const*> reachable = util::BreadthFirstSearch<CFGNode const*>{{_entry}}.run(
[](CFGNode const* _node, auto&& _addChild) {
for (CFGNode const* exit: _node->exits)
_addChild(exit);
@@ -161,7 +161,7 @@ void ControlFlowAnalyzer::checkUnreachable(CFGNode const* _entry, CFGNode const*
// traverse all paths backwards from exit and revert
// and extract (valid) source locations of unreachable nodes into sorted set
std::set<SourceLocation> unreachable;
BreadthFirstSearch<CFGNode const*>{{_exit, _revert}}.run(
util::BreadthFirstSearch<CFGNode const*>{{_exit, _revert}}.run(
[&](CFGNode const* _node, auto&& _addChild) {
if (!reachable.count(_node) && !_node->location.isEmpty())
unreachable.insert(_node->location);
+1 -4
View File
@@ -20,9 +20,7 @@
#include <libsolidity/analysis/ControlFlowGraph.h>
#include <set>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class ControlFlowAnalyzer: private ASTConstVisitor
@@ -47,4 +45,3 @@ private:
};
}
}
+2 -2
View File
@@ -17,9 +17,9 @@
#include <libsolidity/analysis/ControlFlowBuilder.h>
using namespace dev;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
using namespace std;
ControlFlowBuilder::ControlFlowBuilder(CFG::NodeContainer& _nodeContainer, FunctionFlow const& _functionFlow):
+1 -3
View File
@@ -24,8 +24,7 @@
#include <array>
#include <memory>
namespace dev {
namespace solidity {
namespace solidity::frontend {
/** Helper class that builds the control flow of a function or modifier.
* Modifiers are not yet applied to the functions. This is done in a second
@@ -161,4 +160,3 @@ private:
};
}
}
+2 -2
View File
@@ -22,8 +22,8 @@
#include <algorithm>
using namespace std;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
bool CFG::constructFlow(ASTNode const& _astRoot)
{
+1 -4
View File
@@ -27,9 +27,7 @@
#include <stack>
#include <vector>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -154,4 +152,3 @@ private:
};
}
}
@@ -27,8 +27,8 @@
#include <libdevcore/StringUtils.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
Declaration const* DeclarationContainer::conflictingDeclaration(
Declaration const& _declaration,
@@ -118,7 +118,7 @@ bool DeclarationContainer::registerDeclaration(
return false;
vector<Declaration const*>& decls = _invisible ? m_invisibleDeclarations[*_name] : m_declarations[*_name];
if (!contains(decls, &_declaration))
if (!util::contains(decls, &_declaration))
decls.push_back(&_declaration);
return true;
}
@@ -148,13 +148,13 @@ vector<ASTString> DeclarationContainer::similarNames(ASTString const& _name) con
for (auto const& declaration: m_declarations)
{
string const& declarationName = declaration.first;
if (stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD))
if (util::stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD))
similar.push_back(declarationName);
}
for (auto const& declaration: m_invisibleDeclarations)
{
string const& declarationName = declaration.first;
if (stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD))
if (util::stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD))
similar.push_back(declarationName);
}
+1 -4
View File
@@ -27,9 +27,7 @@
#include <map>
#include <set>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -76,4 +74,3 @@ private:
};
}
}
+3 -3
View File
@@ -28,9 +28,9 @@
#include <liblangutil/ErrorReporter.h>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
bool DocStringAnalyser::analyseDocStrings(SourceUnit const& _sourceUnit)
{
+2 -5
View File
@@ -25,14 +25,12 @@
#include <libsolidity/ast/ASTVisitor.h>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -82,4 +80,3 @@ private:
};
}
}
+1 -4
View File
@@ -30,9 +30,7 @@
using namespace std;
namespace dev
{
namespace solidity
namespace solidity::frontend
{
inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariables()
@@ -112,4 +110,3 @@ MagicVariableDeclaration const* GlobalContext::currentSuper() const
}
}
}
+1 -4
View File
@@ -29,9 +29,7 @@
#include <string>
#include <vector>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class Type; // forward
@@ -61,4 +59,3 @@ private:
};
}
}
+4 -7
View File
@@ -29,11 +29,9 @@
#include <boost/algorithm/string.hpp>
using namespace std;
using namespace langutil;
using namespace solidity::langutil;
namespace dev
{
namespace solidity
namespace solidity::frontend
{
NameAndTypeResolver::NameAndTypeResolver(
@@ -244,7 +242,7 @@ vector<Declaration const*> NameAndTypeResolver::cleanedDeclarations(
void NameAndTypeResolver::warnVariablesNamedLikeInstructions()
{
for (auto const& instruction: dev::eth::c_instructions)
for (auto const& instruction: evmasm::c_instructions)
{
string const instructionName{boost::algorithm::to_lower_copy(instruction.first)};
auto declarations = nameFromCurrentScope(instructionName, true);
@@ -460,7 +458,7 @@ vector<_T const*> NameAndTypeResolver::cThreeMerge(list<list<_T const*>>& _toMer
string NameAndTypeResolver::similarNameSuggestions(ASTString const& _name) const
{
return quotedAlternativesList(m_currentScope->similarNames(_name));
return util::quotedAlternativesList(m_currentScope->similarNames(_name));
}
DeclarationRegistrationHelper::DeclarationRegistrationHelper(
@@ -786,4 +784,3 @@ string DeclarationRegistrationHelper::currentCanonicalName() const
}
}
}
+2 -5
View File
@@ -35,14 +35,12 @@
#include <list>
#include <map>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -214,4 +212,3 @@ private:
};
}
}
+7 -3
View File
@@ -32,9 +32,13 @@
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
using namespace solidity::langutil;
using solidity::util::GenericVisitor;
using solidity::util::contains_if;
using solidity::util::joinHumanReadable;
namespace
{
+2 -5
View File
@@ -29,15 +29,13 @@
#include <variant>
#include <optional>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
struct SourceLocation;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class FunctionType;
class ModifierType;
@@ -193,4 +191,3 @@ private:
};
}
}
+5 -5
View File
@@ -27,9 +27,9 @@
#include <memory>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
bool PostTypeChecker::check(ASTNode const& _astRoot)
{
@@ -128,7 +128,7 @@ struct ConstStateVarCircularReferenceChecker: public PostTypeChecker::Checker
VariableDeclaration const* findCycle(VariableDeclaration const& _startingFrom)
{
auto visitor = [&](VariableDeclaration const& _variable, CycleDetector<VariableDeclaration>& _cycleDetector, size_t _depth)
auto visitor = [&](VariableDeclaration const& _variable, util::CycleDetector<VariableDeclaration>& _cycleDetector, size_t _depth)
{
if (_depth >= 256)
m_errorReporter.fatalDeclarationError(_variable.location(), "Variable definition exhausting cyclic dependency validator.");
@@ -148,7 +148,7 @@ struct ConstStateVarCircularReferenceChecker: public PostTypeChecker::Checker
if (_cycleDetector.run(*v))
return;
};
return CycleDetector<VariableDeclaration>(visitor).run(_startingFrom);
return util::CycleDetector<VariableDeclaration>(visitor).run(_startingFrom);
}
private:
+2 -5
View File
@@ -23,15 +23,13 @@
#include <libsolidity/ast/ASTForward.h>
#include <libsolidity/ast/ASTVisitor.h>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
struct SourceLocation;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -93,4 +91,3 @@ private:
};
}
}
+3 -6
View File
@@ -40,11 +40,9 @@
#include <boost/range/adaptor/transformed.hpp>
using namespace std;
using namespace langutil;
using namespace solidity::langutil;
namespace dev
{
namespace solidity
namespace solidity::frontend
{
bool ReferencesResolver::resolve(ASTNode const& _root)
@@ -405,7 +403,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
else
{
errorString = "Data location must be " +
joinHumanReadable(
util::joinHumanReadable(
allowedDataLocations | boost::adaptors::transformed(locationToString),
", ",
" or "
@@ -501,4 +499,3 @@ void ReferencesResolver::fatalDeclarationError(SourceLocation const& _location,
}
}
}
+2 -5
View File
@@ -30,15 +30,13 @@
#include <list>
#include <map>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
struct SourceLocation;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class NameAndTypeResolver;
@@ -110,4 +108,3 @@ private:
};
}
}
+4 -4
View File
@@ -28,14 +28,14 @@
#include <memory>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
/**
* Helper class that determines whether a contract's constructor uses inline assembly.
*/
class dev::solidity::ConstructorUsesAssembly
class solidity::frontend::ConstructorUsesAssembly
{
public:
/// @returns true if and only if the contract's or any of its bases' constructors
+2 -5
View File
@@ -28,14 +28,12 @@
#include <libsolidity/ast/ASTForward.h>
#include <libsolidity/ast/ASTVisitor.h>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class ConstructorUsesAssembly;
@@ -102,4 +100,3 @@ private:
};
}
}
+3 -3
View File
@@ -34,9 +34,9 @@
#include <string>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
bool SyntaxChecker::checkSyntax(ASTNode const& _astRoot)
+2 -5
View File
@@ -23,14 +23,12 @@
#include <libsolidity/ast/ASTForward.h>
#include <libsolidity/ast/ASTVisitor.h>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -109,4 +107,3 @@ private:
};
}
}
+4 -3
View File
@@ -42,9 +42,10 @@
#include <vector>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
using namespace solidity::frontend;
bool TypeChecker::typeSupportedByOldABIEncoder(Type const& _type, bool _isLibraryCall)
{
+2 -5
View File
@@ -29,14 +29,12 @@
#include <libsolidity/ast/ASTVisitor.h>
#include <libsolidity/ast/Types.h>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -179,4 +177,3 @@ private:
};
}
}
+6 -6
View File
@@ -26,9 +26,9 @@
#include <variant>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
namespace
{
@@ -110,11 +110,11 @@ public:
}
private:
void checkInstruction(SourceLocation _location, dev::eth::Instruction _instruction)
void checkInstruction(SourceLocation _location, evmasm::Instruction _instruction)
{
if (eth::SemanticInformation::invalidInViewFunctions(_instruction))
if (evmasm::SemanticInformation::invalidInViewFunctions(_instruction))
m_reportMutability(StateMutability::NonPayable, _location);
else if (eth::SemanticInformation::invalidInPureFunctions(_instruction))
else if (evmasm::SemanticInformation::invalidInPureFunctions(_instruction))
m_reportMutability(StateMutability::View, _location);
}
+2 -5
View File
@@ -25,15 +25,13 @@
#include <memory>
#include <optional>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
struct SourceLocation;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class ViewPureChecker: private ASTConstVisitor
@@ -82,4 +80,3 @@ private:
};
}
}
+9 -9
View File
@@ -32,8 +32,8 @@
#include <functional>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
class IDDispenser
{
@@ -114,11 +114,11 @@ vector<VariableDeclaration const*> ContractDefinition::stateVariablesIncludingIn
return stateVars;
}
map<FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions() const
map<util::FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions() const
{
auto exportedFunctionList = interfaceFunctionList();
map<FixedHash<4>, FunctionTypePointer> exportedFunctions;
map<util::FixedHash<4>, FunctionTypePointer> exportedFunctions;
for (auto const& it: exportedFunctionList)
exportedFunctions.insert(it);
@@ -192,12 +192,12 @@ vector<EventDefinition const*> const& ContractDefinition::interfaceEvents() cons
return *m_interfaceEvents;
}
vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::interfaceFunctionList() const
vector<pair<util::FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::interfaceFunctionList() const
{
if (!m_interfaceFunctionList)
{
set<string> signaturesSeen;
m_interfaceFunctionList = make_unique<vector<pair<FixedHash<4>, FunctionTypePointer>>>();
m_interfaceFunctionList = make_unique<vector<pair<util::FixedHash<4>, FunctionTypePointer>>>();
for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
{
vector<FunctionTypePointer> functions;
@@ -216,7 +216,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::inter
if (signaturesSeen.count(functionSignature) == 0)
{
signaturesSeen.insert(functionSignature);
FixedHash<4> hash(dev::keccak256(functionSignature));
util::FixedHash<4> hash(util::keccak256(functionSignature));
m_interfaceFunctionList->emplace_back(hash, fun);
}
}
@@ -749,7 +749,7 @@ bool Literal::looksLikeAddress() const
bool Literal::passesAddressChecksum() const
{
solAssert(isHexNumber(), "Expected hex number");
return dev::passesAddressChecksum(valueWithoutUnderscores(), true);
return util::passesAddressChecksum(valueWithoutUnderscores(), true);
}
string Literal::getChecksummedAddress() const
@@ -760,5 +760,5 @@ string Literal::getChecksummedAddress() const
if (address.length() > 40)
return string();
address.insert(address.begin(), 40 - address.size(), '0');
return dev::getChecksummedAddress(address);
return util::getChecksummedAddress(address);
}
+5 -9
View File
@@ -40,16 +40,14 @@
#include <string>
#include <vector>
namespace yul
namespace solidity::yul
{
// Forward-declaration to <yul/AsmData.h>
struct Block;
struct Dialect;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class ASTVisitor;
@@ -416,8 +414,8 @@ public:
/// @returns a map of canonical function signatures to FunctionDefinitions
/// as intended for use by the ABI.
std::map<FixedHash<4>, FunctionTypePointer> interfaceFunctions() const;
std::vector<std::pair<FixedHash<4>, FunctionTypePointer>> const& interfaceFunctionList() const;
std::map<util::FixedHash<4>, FunctionTypePointer> interfaceFunctions() const;
std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>> const& interfaceFunctionList() const;
/// @returns a list of the inheritable members of this contract
std::vector<Declaration const*> const& inheritableMembers() const;
@@ -452,7 +450,7 @@ private:
ContractKind m_contractKind;
bool m_abstract{false};
mutable std::unique_ptr<std::vector<std::pair<FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList;
mutable std::unique_ptr<std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList;
mutable std::unique_ptr<std::vector<EventDefinition const*>> m_interfaceEvents;
mutable std::unique_ptr<std::vector<Declaration const*>> m_inheritableMembers;
};
@@ -1905,6 +1903,4 @@ private:
/// @}
}
}
+2 -2
View File
@@ -23,6 +23,6 @@
#include <libsolidity/ast/ASTAnnotations.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
+2 -5
View File
@@ -32,16 +32,14 @@
#include <set>
#include <vector>
namespace yul
namespace solidity::yul
{
struct AsmAnalysisInfo;
struct Identifier;
struct Dialect;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class Type;
@@ -252,4 +250,3 @@ struct FunctionCallAnnotation: ExpressionAnnotation
};
}
}
+1 -4
View File
@@ -26,9 +26,7 @@
#include <string>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
// How a function can mutate the EVM state.
@@ -70,4 +68,3 @@ struct FuncCallArguments
};
}
}
+2 -5
View File
@@ -28,14 +28,12 @@
// Forward-declare all AST node types and related enums.
namespace langutil
namespace solidity::langutil
{
enum class Token : unsigned int;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class ASTNode;
@@ -107,4 +105,3 @@ using ASTPointer = std::shared_ptr<T>;
using ASTString = std::string;
}
}
+10 -13
View File
@@ -36,11 +36,9 @@
#include <algorithm>
using namespace std;
using namespace langutil;
using namespace solidity::langutil;
namespace dev
{
namespace solidity
namespace solidity::frontend
{
ASTJsonConverter::ASTJsonConverter(bool _legacy, map<string, unsigned> _sourceIndices):
@@ -200,7 +198,7 @@ Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair<yul::Identifie
void ASTJsonConverter::print(ostream& _stream, ASTNode const& _node)
{
_stream << jsonPrettyPrint(toJson(_node));
_stream << util::jsonPrettyPrint(toJson(_node));
}
Json::Value&& ASTJsonConverter::toJson(ASTNode const& _node)
@@ -792,13 +790,13 @@ bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node)
bool ASTJsonConverter::visit(Literal const& _node)
{
Json::Value value{_node.value()};
if (!dev::validateUTF8(_node.value()))
if (!util::validateUTF8(_node.value()))
value = Json::nullValue;
Token subdenomination = Token(_node.subDenomination());
std::vector<pair<string, Json::Value>> attributes = {
make_pair(m_legacy ? "token" : "kind", literalTokenKind(_node.token())),
make_pair("value", value),
make_pair(m_legacy ? "hexvalue" : "hexValue", toHex(asBytes(_node.value()))),
make_pair(m_legacy ? "hexvalue" : "hexValue", util::toHex(util::asBytes(_node.value()))),
make_pair(
"subdenomination",
subdenomination == Token::Illegal ?
@@ -869,13 +867,13 @@ string ASTJsonConverter::literalTokenKind(Token _token)
{
switch (_token)
{
case dev::solidity::Token::Number:
case Token::Number:
return "number";
case dev::solidity::Token::StringLiteral:
case dev::solidity::Token::HexStringLiteral:
case Token::StringLiteral:
case Token::HexStringLiteral:
return "string";
case dev::solidity::Token::TrueLiteral:
case dev::solidity::Token::FalseLiteral:
case Token::TrueLiteral:
case Token::FalseLiteral:
return "bool";
default:
solAssert(false, "Unknown kind of literal token.");
@@ -893,4 +891,3 @@ string ASTJsonConverter::type(VariableDeclaration const& _varDecl)
}
}
}
+2 -5
View File
@@ -34,14 +34,12 @@
#include <stack>
#include <vector>
namespace langutil
namespace solidity::langutil
{
struct SourceLocation;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -194,4 +192,3 @@ private:
};
}
}
+1 -4
View File
@@ -18,9 +18,7 @@
#include <libsolidity/ast/AST.h>
#include <libsolidity/ast/ASTUtils.h>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
VariableDeclaration const* rootVariableDeclaration(VariableDeclaration const& _varDecl)
@@ -39,4 +37,3 @@ VariableDeclaration const* rootVariableDeclaration(VariableDeclaration const& _v
}
}
}
+3 -4
View File
@@ -17,14 +17,13 @@
#pragma once
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class VariableDeclaration;
/// Find the topmost referenced variable declaration when the given variable
/// declaration value is an identifier. Works only for constant variable declarations.
VariableDeclaration const* rootVariableDeclaration(VariableDeclaration const& _varDecl);
}
}
+1 -4
View File
@@ -27,9 +27,7 @@
#include <string>
#include <vector>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -329,4 +327,3 @@ private:
};
}
}
+1 -4
View File
@@ -26,9 +26,7 @@
#include <libsolidity/ast/AST.h>
#include <libsolidity/ast/ASTVisitor.h>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
void SourceUnit::accept(ASTVisitor& _visitor)
@@ -896,4 +894,3 @@ void Literal::accept(ASTConstVisitor& _visitor) const
}
}
}
+1 -4
View File
@@ -23,9 +23,7 @@
#include <map>
#include <set>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
enum class ExperimentalFeature
@@ -52,4 +50,3 @@ static std::map<std::string, ExperimentalFeature> const ExperimentalFeatureNames
};
}
}
+2 -1
View File
@@ -21,8 +21,9 @@
#include <boost/algorithm/string/split.hpp>
using namespace std;
using namespace dev;
using namespace solidity;
using namespace solidity::frontend;
using namespace solidity::util;
BoolType const TypeProvider::m_boolean{};
InaccessibleDynamicType const TypeProvider::m_inaccessibleDynamic{};
+2 -5
View File
@@ -25,9 +25,7 @@
#include <optional>
#include <utility>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -225,5 +223,4 @@ private:
std::vector<std::unique_ptr<Type>> m_generalTypes{};
};
} // namespace solidity
} // namespace dev
}
+27 -27
View File
@@ -45,9 +45,9 @@
#include <limits>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
namespace
{
@@ -131,7 +131,7 @@ bool fitsIntoBits(bigint const& _value, unsigned _bits, bool _signed)
));
}
Result<TypePointers> transformParametersToExternal(TypePointers const& _parameters, bool _inLibrary)
util::Result<TypePointers> transformParametersToExternal(TypePointers const& _parameters, bool _inLibrary)
{
TypePointers transformed;
@@ -140,7 +140,7 @@ Result<TypePointers> transformParametersToExternal(TypePointers const& _paramete
if (TypePointer ext = type->interfaceType(_inLibrary).get())
transformed.push_back(ext);
else
return Result<TypePointers>::err("Parameter should have external type.");
return util::Result<TypePointers>::err("Parameter should have external type.");
}
return transformed;
@@ -170,7 +170,7 @@ void StorageOffsets::computeOffsets(TypePointers const& _types)
byteOffset = 0;
}
if (slotOffset >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << errinfo_comment("Object too large for storage."));
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << util::errinfo_comment("Object too large for storage."));
offsets[i] = make_pair(u256(slotOffset), byteOffset);
solAssert(type->storageSize() >= 1, "Invalid storage size.");
if (type->storageSize() == 1 && byteOffset + type->storageBytes() <= 32)
@@ -184,7 +184,7 @@ void StorageOffsets::computeOffsets(TypePointers const& _types)
if (byteOffset > 0)
++slotOffset;
if (slotOffset >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << errinfo_comment("Object too large for storage."));
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << util::errinfo_comment("Object too large for storage."));
m_storageSize = u256(slotOffset);
swap(m_offsets, offsets);
}
@@ -486,7 +486,7 @@ IntegerType::IntegerType(unsigned _bits, IntegerType::Modifier _modifier):
{
solAssert(
m_bits > 0 && m_bits <= 256 && m_bits % 8 == 0,
"Invalid bit number for integer type: " + dev::toString(m_bits)
"Invalid bit number for integer type: " + util::toString(m_bits)
);
}
@@ -550,7 +550,7 @@ bool IntegerType::operator==(Type const& _other) const
string IntegerType::toString(bool) const
{
string prefix = isSigned() ? "int" : "uint";
return prefix + dev::toString(m_bits);
return prefix + util::toString(m_bits);
}
bigint IntegerType::minValue() const
@@ -615,7 +615,7 @@ FixedPointType::FixedPointType(unsigned _totalBits, unsigned _fractionalDigits,
solAssert(
8 <= m_totalBits && m_totalBits <= 256 && m_totalBits % 8 == 0 && m_fractionalDigits <= 80,
"Invalid bit number(s) for fixed type: " +
dev::toString(_totalBits) + "x" + dev::toString(_fractionalDigits)
util::toString(_totalBits) + "x" + util::toString(_fractionalDigits)
);
}
@@ -673,7 +673,7 @@ bool FixedPointType::operator==(Type const& _other) const
string FixedPointType::toString(bool) const
{
string prefix = isSigned() ? "fixed" : "ufixed";
return prefix + dev::toString(m_totalBits) + "x" + dev::toString(m_fractionalDigits);
return prefix + util::toString(m_totalBits) + "x" + util::toString(m_fractionalDigits);
}
bigint FixedPointType::maxIntegerValue() const
@@ -1134,7 +1134,7 @@ bool RationalNumberType::operator==(Type const& _other) const
return m_value == other.m_value;
}
string RationalNumberType::bigintToReadableString(dev::bigint const& _num)
string RationalNumberType::bigintToReadableString(bigint const& _num)
{
string str = _num.str();
if (str.size() > 32)
@@ -1203,7 +1203,7 @@ IntegerType const* RationalNumberType::integerType() const
return nullptr;
else
return TypeProvider::integer(
max(bytesRequired(value), 1u) * 8,
max(util::bytesRequired(value), 1u) * 8,
negative ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned
);
}
@@ -1237,7 +1237,7 @@ FixedPointType const* RationalNumberType::fixedPointType() const
if (v > u256(-1))
return nullptr;
unsigned totalBits = max(bytesRequired(v), 1u) * 8;
unsigned totalBits = max(util::bytesRequired(v), 1u) * 8;
solAssert(totalBits <= 256, "");
return TypeProvider::fixedPoint(
@@ -1273,7 +1273,7 @@ string StringLiteralType::richIdentifier() const
{
// Since we have to return a valid identifier and the string itself may contain
// anything, we hash it.
return "t_stringliteral_" + toHex(keccak256(m_value).asBytes());
return "t_stringliteral_" + util::toHex(util::keccak256(m_value).asBytes());
}
bool StringLiteralType::operator==(Type const& _other) const
@@ -1287,8 +1287,8 @@ std::string StringLiteralType::toString(bool) const
{
size_t invalidSequence;
if (!dev::validateUTF8(m_value, invalidSequence))
return "literal_string (contains invalid UTF-8 sequence at position " + dev::toString(invalidSequence) + ")";
if (!util::validateUTF8(m_value, invalidSequence))
return "literal_string (contains invalid UTF-8 sequence at position " + util::toString(invalidSequence) + ")";
return "literal_string \"" + m_value + "\"";
}
@@ -1300,14 +1300,14 @@ TypePointer StringLiteralType::mobileType() const
bool StringLiteralType::isValidUTF8() const
{
return dev::validateUTF8(m_value);
return util::validateUTF8(m_value);
}
FixedBytesType::FixedBytesType(unsigned _bytes): m_bytes(_bytes)
{
solAssert(
m_bytes > 0 && m_bytes <= 32,
"Invalid byte number for fixed bytes type: " + dev::toString(m_bytes)
"Invalid byte number for fixed bytes type: " + util::toString(m_bytes)
);
}
@@ -1697,7 +1697,7 @@ u256 ArrayType::storageSize() const
else
size = bigint(length()) * baseType()->storageSize();
if (size >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << errinfo_comment("Array too large for storage."));
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << util::errinfo_comment("Array too large for storage."));
return max<u256>(1, u256(size));
}
@@ -2145,7 +2145,7 @@ TypeResult StructType::interfaceType(bool _inLibrary) const
auto visitor = [&](
StructDefinition const& _struct,
CycleDetector<StructDefinition>& _cycleDetector,
util::CycleDetector<StructDefinition>& _cycleDetector,
size_t /*_depth*/
)
{
@@ -2193,7 +2193,7 @@ TypeResult StructType::interfaceType(bool _inLibrary) const
}
};
m_recursive = m_recursive.value() || (CycleDetector<StructDefinition>(visitor).run(structDefinition()) != nullptr);
m_recursive = m_recursive.value() || (util::CycleDetector<StructDefinition>(visitor).run(structDefinition()) != nullptr);
std::string const recursiveErrMsg = "Recursive type not allowed for public or external contract functions.";
@@ -2338,7 +2338,7 @@ unsigned EnumType::storageBytes() const
if (elements <= 1)
return 1;
else
return dev::bytesRequired(elements - 1);
return util::bytesRequired(elements - 1);
}
string EnumType::toString(bool) const
@@ -2908,13 +2908,13 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const
solAssert(m_declaration, "Declaration needed to determine interface function type.");
bool isLibraryFunction = kind() != Kind::Event && dynamic_cast<ContractDefinition const&>(*m_declaration->scope()).isLibrary();
Result<TypePointers> paramTypes =
util::Result<TypePointers> paramTypes =
transformParametersToExternal(m_parameterTypes, isLibraryFunction);
if (!paramTypes.message().empty())
return FunctionTypePointer();
Result<TypePointers> retParamTypes =
util::Result<TypePointers> retParamTypes =
transformParametersToExternal(m_returnParameterTypes, isLibraryFunction);
if (!retParamTypes.message().empty())
@@ -3171,12 +3171,12 @@ string FunctionType::externalSignature() const
u256 FunctionType::externalIdentifier() const
{
return FixedHash<4>::Arith(FixedHash<4>(dev::keccak256(externalSignature())));
return util::FixedHash<4>::Arith(util::FixedHash<4>(util::keccak256(externalSignature())));
}
string FunctionType::externalIdentifierHex() const
{
return FixedHash<4>(dev::keccak256(externalSignature())).hex();
return util::FixedHash<4>(util::keccak256(externalSignature())).hex();
}
bool FunctionType::isPure() const
+6 -9
View File
@@ -39,9 +39,7 @@
#include <set>
#include <string>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class TypeProvider;
@@ -50,9 +48,9 @@ class FunctionType; // forward
using TypePointer = Type const*;
using FunctionTypePointer = FunctionType const*;
using TypePointers = std::vector<TypePointer>;
using rational = boost::rational<dev::bigint>;
using TypeResult = Result<TypePointer>;
using BoolResult = Result<bool>;
using rational = boost::rational<bigint>;
using TypeResult = util::Result<TypePointer>;
using BoolResult = util::Result<bool>;
inline rational makeRational(bigint const& _numerator, bigint const& _denominator)
{
@@ -539,7 +537,7 @@ private:
/// @returns a truncated readable representation of the bigint keeping only
/// up to 4 leading and 4 trailing digits.
static std::string bigintToReadableString(dev::bigint const& num);
static std::string bigintToReadableString(bigint const& num);
};
/**
@@ -599,7 +597,7 @@ public:
bool leftAligned() const override { return true; }
bool isValueType() const override { return true; }
std::string toString(bool) const override { return "bytes" + dev::toString(m_bytes); }
std::string toString(bool) const override { return "bytes" + util::toString(m_bytes); }
MemberList::MemberMap nativeMembers(ContractDefinition const*) const override;
TypePointer encodingType() const override { return this; }
TypeResult interfaceType(bool) const override { return this; }
@@ -1445,4 +1443,3 @@ public:
};
}
}
+3 -2
View File
@@ -31,8 +31,9 @@
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
string ABIFunctions::tupleEncoder(
TypePointers const& _givenTypes,
+1 -4
View File
@@ -32,9 +32,7 @@
#include <set>
#include <vector>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class Type;
@@ -258,4 +256,3 @@ private:
};
}
}
+24 -24
View File
@@ -32,10 +32,10 @@
#include <liblangutil/Exceptions.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::frontend;
using namespace solidity::langutil;
void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType const& _sourceType) const
{
@@ -119,14 +119,14 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons
_context << Instruction::SWAP3;
// stack: target_ref target_data_end source_length target_data_pos source_ref
eth::AssemblyItem copyLoopEndWithoutByteOffset = _context.newTag();
evmasm::AssemblyItem copyLoopEndWithoutByteOffset = _context.newTag();
// special case for short byte arrays: Store them together with their length.
if (_targetType.isByteArray())
{
// stack: target_ref target_data_end source_length target_data_pos source_ref
_context << Instruction::DUP3 << u256(31) << Instruction::LT;
eth::AssemblyItem longByteArray = _context.appendConditionalJump();
evmasm::AssemblyItem longByteArray = _context.appendConditionalJump();
// store the short byte array
solAssert(_sourceType.isByteArray(), "");
if (_sourceType.location() == DataLocation::Storage)
@@ -172,13 +172,13 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons
if (haveByteOffsetSource)
_context << u256(0);
// stack: target_ref target_data_end source_data_pos target_data_pos source_data_end [target_byte_offset] [source_byte_offset]
eth::AssemblyItem copyLoopStart = _context.newTag();
evmasm::AssemblyItem copyLoopStart = _context.newTag();
_context << copyLoopStart;
// check for loop condition
_context
<< dupInstruction(3 + byteOffsetSize) << dupInstruction(2 + byteOffsetSize)
<< Instruction::GT << Instruction::ISZERO;
eth::AssemblyItem copyLoopEnd = _context.appendConditionalJump();
evmasm::AssemblyItem copyLoopEnd = _context.appendConditionalJump();
// stack: target_ref target_data_end source_data_pos target_data_pos source_data_end [target_byte_offset] [source_byte_offset]
// copy
if (sourceBaseType->category() == Type::Category::Array)
@@ -264,7 +264,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons
// clear elements that might be left over in the current slot in target
// stack: target_ref target_data_end source_data_pos target_data_pos source_data_end target_byte_offset [source_byte_offset]
_context << dupInstruction(byteOffsetSize) << Instruction::ISZERO;
eth::AssemblyItem copyCleanupLoopEnd = _context.appendConditionalJump();
evmasm::AssemblyItem copyCleanupLoopEnd = _context.appendConditionalJump();
_context << dupInstruction(2 + byteOffsetSize) << dupInstruction(1 + byteOffsetSize);
StorageItem(_context, *targetBaseType).setToZero(SourceLocation(), true);
utils.incrementByteOffset(targetBaseType->storageBytes(), byteOffsetSize, byteOffsetSize + 2);
@@ -375,7 +375,7 @@ void ArrayUtils::copyArrayToMemory(ArrayType const& _sourceType, bool _padToWord
// stack: <length> <target + size>
m_context << Instruction::SWAP1 << u256(31) << Instruction::AND;
// stack: <target + size> <remainder = size % 32>
eth::AssemblyItem skip = m_context.newTag();
evmasm::AssemblyItem skip = m_context.newTag();
if (_sourceType.isDynamicallySized())
{
m_context << Instruction::DUP1 << Instruction::ISZERO;
@@ -420,13 +420,13 @@ void ArrayUtils::copyArrayToMemory(ArrayType const& _sourceType, bool _padToWord
// stack here: memory_offset storage_offset length
// jump to end if length is zero
m_context << Instruction::DUP1 << Instruction::ISZERO;
eth::AssemblyItem loopEnd = m_context.appendConditionalJump();
evmasm::AssemblyItem loopEnd = m_context.appendConditionalJump();
// Special case for tightly-stored byte arrays
if (_sourceType.isByteArray())
{
// stack here: memory_offset storage_offset length
m_context << Instruction::DUP1 << u256(31) << Instruction::LT;
eth::AssemblyItem longByteArray = m_context.appendConditionalJump();
evmasm::AssemblyItem longByteArray = m_context.appendConditionalJump();
// store the short byte array (discard lower-order byte)
m_context << u256(0x100) << Instruction::DUP1;
m_context << Instruction::DUP4 << Instruction::SLOAD;
@@ -462,7 +462,7 @@ void ArrayUtils::copyArrayToMemory(ArrayType const& _sourceType, bool _padToWord
if (haveByteOffset)
m_context << u256(0) << Instruction::SWAP1;
// stack here: memory_end_offset storage_data_offset [storage_byte_offset] memory_offset
eth::AssemblyItem loopStart = m_context.newTag();
evmasm::AssemblyItem loopStart = m_context.newTag();
m_context << loopStart;
// load and store
if (_sourceType.isByteArray())
@@ -599,12 +599,12 @@ void ArrayUtils::clearDynamicArray(ArrayType const& _type) const
// set length to zero
m_context << u256(0) << Instruction::DUP3 << Instruction::SSTORE;
// Special case: short byte arrays are stored togeher with their length
eth::AssemblyItem endTag = m_context.newTag();
evmasm::AssemblyItem endTag = m_context.newTag();
if (_type.isByteArray())
{
// stack: ref old_length
m_context << Instruction::DUP1 << u256(31) << Instruction::LT;
eth::AssemblyItem longByteArray = m_context.appendConditionalJump();
evmasm::AssemblyItem longByteArray = m_context.appendConditionalJump();
m_context << Instruction::POP;
m_context.appendJumpTo(endTag);
m_context.adjustStackOffset(1); // needed because of jump
@@ -644,7 +644,7 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
solAssert(_type.baseType()->isValueType(), "Invalid storage size for non-value type.");
unsigned stackHeightStart = _context.stackHeight();
eth::AssemblyItem resizeEnd = _context.newTag();
evmasm::AssemblyItem resizeEnd = _context.newTag();
// stack: ref new_length
// fetch old length
@@ -655,7 +655,7 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
// Special case for short byte arrays, they are stored together with their length
if (_type.isByteArray())
{
eth::AssemblyItem regularPath = _context.newTag();
evmasm::AssemblyItem regularPath = _context.newTag();
// We start by a large case-distinction about the old and new length of the byte array.
_context << Instruction::DUP3 << Instruction::SLOAD;
@@ -663,14 +663,14 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
solAssert(_context.stackHeight() - stackHeightStart == 4 - 2, "3");
_context << Instruction::DUP2 << u256(31) << Instruction::LT;
eth::AssemblyItem currentIsLong = _context.appendConditionalJump();
evmasm::AssemblyItem currentIsLong = _context.appendConditionalJump();
_context << Instruction::DUP3 << u256(31) << Instruction::LT;
eth::AssemblyItem newIsLong = _context.appendConditionalJump();
evmasm::AssemblyItem newIsLong = _context.appendConditionalJump();
// Here: short -> short
// Compute 1 << (256 - 8 * new_size)
eth::AssemblyItem shortToShort = _context.newTag();
evmasm::AssemblyItem shortToShort = _context.newTag();
_context << shortToShort;
_context << Instruction::DUP3 << u256(8) << Instruction::MUL;
_context << u256(0x100) << Instruction::SUB;
@@ -928,11 +928,11 @@ void ArrayUtils::clearStorageLoop(TypePointer _type) const
// stack: end_pos pos
// jump to and return from the loop to allow for duplicate code removal
eth::AssemblyItem returnTag = _context.pushNewTag();
evmasm::AssemblyItem returnTag = _context.pushNewTag();
_context << Instruction::SWAP2 << Instruction::SWAP1;
// stack: <return tag> end_pos pos
eth::AssemblyItem loopStart = _context.appendJumpToNew();
evmasm::AssemblyItem loopStart = _context.appendJumpToNew();
_context << loopStart;
// check for loop condition
_context <<
@@ -940,7 +940,7 @@ void ArrayUtils::clearStorageLoop(TypePointer _type) const
Instruction::DUP3 <<
Instruction::GT <<
Instruction::ISZERO;
eth::AssemblyItem zeroLoopEnd = _context.newTag();
evmasm::AssemblyItem zeroLoopEnd = _context.newTag();
_context.appendConditionalJumpTo(zeroLoopEnd);
// delete
_context << u256(0);
@@ -1082,7 +1082,7 @@ void ArrayUtils::accessIndex(ArrayType const& _arrayType, bool _doBoundsCheck, b
m_context << Instruction::SWAP1;
// stack: [<base_ref>] <index> <base_ref>
eth::AssemblyItem endTag = m_context.newTag();
evmasm::AssemblyItem endTag = m_context.newTag();
if (_arrayType.isByteArray())
{
// Special case of short byte arrays.
+1 -4
View File
@@ -24,9 +24,7 @@
#include <memory>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class CompilerContext;
@@ -120,4 +118,3 @@ private:
};
}
}
+4 -4
View File
@@ -26,8 +26,8 @@
#include <libevmasm/Assembly.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
void Compiler::compileContract(
ContractDefinition const& _contract,
@@ -51,13 +51,13 @@ void Compiler::compileContract(
m_context.optimise(m_optimiserSettings);
}
std::shared_ptr<eth::Assembly> Compiler::runtimeAssemblyPtr() const
std::shared_ptr<evmasm::Assembly> Compiler::runtimeAssemblyPtr() const
{
solAssert(m_context.runtimeContext(), "");
return m_context.runtimeContext()->assemblyPtr();
}
eth::AssemblyItem Compiler::functionEntryLabel(FunctionDefinition const& _function) const
evmasm::AssemblyItem Compiler::functionEntryLabel(FunctionDefinition const& _function) const
{
return m_runtimeContext.functionEntryLabelIfExists(_function);
}
+9 -11
View File
@@ -30,8 +30,7 @@
#include <functional>
#include <ostream>
namespace dev {
namespace solidity {
namespace solidity::frontend {
class Compiler
{
@@ -51,15 +50,15 @@ public:
bytes const& _metadata
);
/// @returns Entire assembly.
eth::Assembly const& assembly() const { return m_context.assembly(); }
evmasm::Assembly const& assembly() const { return m_context.assembly(); }
/// @returns Entire assembly as a shared pointer to non-const.
std::shared_ptr<eth::Assembly> assemblyPtr() const { return m_context.assemblyPtr(); }
std::shared_ptr<evmasm::Assembly> assemblyPtr() const { return m_context.assemblyPtr(); }
/// @returns Runtime assembly.
std::shared_ptr<eth::Assembly> runtimeAssemblyPtr() const;
std::shared_ptr<evmasm::Assembly> runtimeAssemblyPtr() const;
/// @returns The entire assembled object (with constructor).
eth::LinkerObject assembledObject() const { return m_context.assembledObject(); }
evmasm::LinkerObject assembledObject() const { return m_context.assembledObject(); }
/// @returns Only the runtime object (without constructor).
eth::LinkerObject runtimeObject() const { return m_context.assembledRuntimeObject(m_runtimeSub); }
evmasm::LinkerObject runtimeObject() const { return m_context.assembledRuntimeObject(m_runtimeSub); }
/// @arg _sourceCodes is the map of input files to source code strings
std::string assemblyString(StringMap const& _sourceCodes = StringMap()) const
{
@@ -71,13 +70,13 @@ public:
return m_context.assemblyJSON(_sourceCodes);
}
/// @returns Assembly items of the normal compiler context
eth::AssemblyItems const& assemblyItems() const { return m_context.assembly().items(); }
evmasm::AssemblyItems const& assemblyItems() const { return m_context.assembly().items(); }
/// @returns Assembly items of the runtime compiler context
eth::AssemblyItems const& runtimeAssemblyItems() const { return m_context.assembly().sub(m_runtimeSub).items(); }
evmasm::AssemblyItems const& runtimeAssemblyItems() const { return m_context.assembly().sub(m_runtimeSub).items(); }
/// @returns the entry label of the given function. Might return an AssemblyItem of type
/// UndefinedItem if it does not exist yet.
eth::AssemblyItem functionEntryLabel(FunctionDefinition const& _function) const;
evmasm::AssemblyItem functionEntryLabel(FunctionDefinition const& _function) const;
private:
OptimiserSettings const m_optimiserSettings;
@@ -88,4 +87,3 @@ private:
};
}
}
+23 -23
View File
@@ -54,10 +54,10 @@
using namespace std;
using namespace langutil;
using namespace dev::eth;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::frontend;
using namespace solidity::langutil;
void CompilerContext::addStateVariable(
VariableDeclaration const& _declaration,
@@ -81,17 +81,17 @@ void CompilerContext::callLowLevelFunction(
function<void(CompilerContext&)> const& _generator
)
{
eth::AssemblyItem retTag = pushNewTag();
evmasm::AssemblyItem retTag = pushNewTag();
CompilerUtils(*this).moveIntoStack(_inArgs);
*this << lowLevelFunctionTag(_name, _inArgs, _outArgs, _generator);
appendJump(eth::AssemblyItem::JumpType::IntoFunction);
appendJump(evmasm::AssemblyItem::JumpType::IntoFunction);
adjustStackOffset(int(_outArgs) - 1 - _inArgs);
*this << retTag.tag();
}
eth::AssemblyItem CompilerContext::lowLevelFunctionTag(
evmasm::AssemblyItem CompilerContext::lowLevelFunctionTag(
string const& _name,
unsigned _inArgs,
unsigned _outArgs,
@@ -101,7 +101,7 @@ eth::AssemblyItem CompilerContext::lowLevelFunctionTag(
auto it = m_lowLevelFunctions.find(_name);
if (it == m_lowLevelFunctions.end())
{
eth::AssemblyItem tag = newTag().pushTag();
evmasm::AssemblyItem tag = newTag().pushTag();
m_lowLevelFunctions.insert(make_pair(_name, tag));
m_lowLevelFunctionGenerationQueue.push(make_tuple(_name, _inArgs, _outArgs, _generator));
return tag;
@@ -125,7 +125,7 @@ void CompilerContext::appendMissingLowLevelFunctions()
*this << m_lowLevelFunctions.at(name).tag();
generator(*this);
CompilerUtils(*this).moveToStackTop(outArgs);
appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
appendJump(evmasm::AssemblyItem::JumpType::OutOfFunction);
solAssert(stackHeight() == outArgs, "Invalid stack height in low-level function " + name + ".");
}
}
@@ -170,14 +170,14 @@ unsigned CompilerContext::numberOfLocalVariables() const
return m_localVariables.size();
}
shared_ptr<eth::Assembly> CompilerContext::compiledContract(ContractDefinition const& _contract) const
shared_ptr<evmasm::Assembly> CompilerContext::compiledContract(ContractDefinition const& _contract) const
{
auto ret = m_otherCompilers.find(&_contract);
solAssert(ret != m_otherCompilers.end(), "Compiled contract not found.");
return ret->second->assemblyPtr();
}
shared_ptr<eth::Assembly> CompilerContext::compiledContractRuntime(ContractDefinition const& _contract) const
shared_ptr<evmasm::Assembly> CompilerContext::compiledContractRuntime(ContractDefinition const& _contract) const
{
auto ret = m_otherCompilers.find(&_contract);
solAssert(ret != m_otherCompilers.end(), "Compiled contract not found.");
@@ -189,12 +189,12 @@ bool CompilerContext::isLocalVariable(Declaration const* _declaration) const
return !!m_localVariables.count(_declaration);
}
eth::AssemblyItem CompilerContext::functionEntryLabel(Declaration const& _declaration)
evmasm::AssemblyItem CompilerContext::functionEntryLabel(Declaration const& _declaration)
{
return m_functionCompilationQueue.entryLabel(_declaration, *this);
}
eth::AssemblyItem CompilerContext::functionEntryLabelIfExists(Declaration const& _declaration) const
evmasm::AssemblyItem CompilerContext::functionEntryLabelIfExists(Declaration const& _declaration) const
{
return m_functionCompilationQueue.entryLabelIfExists(_declaration);
}
@@ -275,9 +275,9 @@ pair<u256, unsigned> CompilerContext::storageLocationOfVariable(Declaration cons
return it->second;
}
CompilerContext& CompilerContext::appendJump(eth::AssemblyItem::JumpType _jumpType)
CompilerContext& CompilerContext::appendJump(evmasm::AssemblyItem::JumpType _jumpType)
{
eth::AssemblyItem item(Instruction::JUMP);
evmasm::AssemblyItem item(Instruction::JUMP);
item.setJumpType(_jumpType);
return *this << item;
}
@@ -290,7 +290,7 @@ CompilerContext& CompilerContext::appendInvalid()
CompilerContext& CompilerContext::appendConditionalInvalid()
{
*this << Instruction::ISZERO;
eth::AssemblyItem afterTag = appendConditionalJump();
evmasm::AssemblyItem afterTag = appendConditionalJump();
*this << Instruction::INVALID;
*this << afterTag;
return *this;
@@ -370,7 +370,7 @@ void CompilerContext::appendInlineAssembly(
BOOST_THROW_EXCEPTION(
CompilerError() <<
errinfo_sourceLocation(_identifier.location) <<
errinfo_comment("Stack too deep (" + to_string(stackDiff) + "), try removing local variables.")
util::errinfo_comment("Stack too deep (" + to_string(stackDiff) + "), try removing local variables.")
);
if (_context == yul::IdentifierContext::RValue)
_assembly.appendInstruction(dupInstruction(stackDiff));
@@ -493,10 +493,10 @@ void CompilerContext::updateSourceLocation()
m_asm->setSourceLocation(m_visitedNodes.empty() ? SourceLocation() : m_visitedNodes.top()->location());
}
eth::Assembly::OptimiserSettings CompilerContext::translateOptimiserSettings(OptimiserSettings const& _settings)
evmasm::Assembly::OptimiserSettings CompilerContext::translateOptimiserSettings(OptimiserSettings const& _settings)
{
// Constructing it this way so that we notice changes in the fields.
eth::Assembly::OptimiserSettings asmSettings{false, false, false, false, false, false, m_evmVersion, 0};
evmasm::Assembly::OptimiserSettings asmSettings{false, false, false, false, false, false, m_evmVersion, 0};
asmSettings.isCreation = true;
asmSettings.runJumpdestRemover = _settings.runJumpdestRemover;
asmSettings.runPeephole = _settings.runPeephole;
@@ -508,7 +508,7 @@ eth::Assembly::OptimiserSettings CompilerContext::translateOptimiserSettings(Opt
return asmSettings;
}
eth::AssemblyItem CompilerContext::FunctionCompilationQueue::entryLabel(
evmasm::AssemblyItem CompilerContext::FunctionCompilationQueue::entryLabel(
Declaration const& _declaration,
CompilerContext& _context
)
@@ -516,7 +516,7 @@ eth::AssemblyItem CompilerContext::FunctionCompilationQueue::entryLabel(
auto res = m_entryLabels.find(&_declaration);
if (res == m_entryLabels.end())
{
eth::AssemblyItem tag(_context.newTag());
evmasm::AssemblyItem tag(_context.newTag());
m_entryLabels.insert(make_pair(&_declaration, tag));
m_functionsToCompile.push(&_declaration);
return tag.tag();
@@ -526,10 +526,10 @@ eth::AssemblyItem CompilerContext::FunctionCompilationQueue::entryLabel(
}
eth::AssemblyItem CompilerContext::FunctionCompilationQueue::entryLabelIfExists(Declaration const& _declaration) const
evmasm::AssemblyItem CompilerContext::FunctionCompilationQueue::entryLabelIfExists(Declaration const& _declaration) const
{
auto res = m_entryLabels.find(&_declaration);
return res == m_entryLabels.end() ? eth::AssemblyItem(eth::UndefinedItem) : res->second.tag();
return res == m_entryLabels.end() ? evmasm::AssemblyItem(evmasm::UndefinedItem) : res->second.tag();
}
Declaration const* CompilerContext::FunctionCompilationQueue::nextFunctionToCompile() const
+31 -33
View File
@@ -40,8 +40,7 @@
#include <queue>
#include <utility>
namespace dev {
namespace solidity {
namespace solidity::frontend {
class Compiler;
@@ -53,7 +52,7 @@ class CompilerContext
{
public:
explicit CompilerContext(langutil::EVMVersion _evmVersion, CompilerContext* _runtimeContext = nullptr):
m_asm(std::make_shared<eth::Assembly>()),
m_asm(std::make_shared<evmasm::Assembly>()),
m_evmVersion(_evmVersion),
m_runtimeContext(_runtimeContext),
m_abiFunctions(m_evmVersion)
@@ -78,8 +77,8 @@ public:
unsigned numberOfLocalVariables() const;
void setOtherCompilers(std::map<ContractDefinition const*, std::shared_ptr<Compiler const>> const& _otherCompilers) { m_otherCompilers = _otherCompilers; }
std::shared_ptr<eth::Assembly> compiledContract(ContractDefinition const& _contract) const;
std::shared_ptr<eth::Assembly> compiledContractRuntime(ContractDefinition const& _contract) const;
std::shared_ptr<evmasm::Assembly> compiledContract(ContractDefinition const& _contract) const;
std::shared_ptr<evmasm::Assembly> compiledContractRuntime(ContractDefinition const& _contract) const;
void setStackOffset(int _offset) { m_asm->setDeposit(_offset); }
void adjustStackOffset(int _adjustment) { m_asm->adjustDeposit(_adjustment); }
@@ -89,10 +88,10 @@ public:
bool isStateVariable(Declaration const* _declaration) const { return m_stateVariables.count(_declaration) != 0; }
/// @returns the entry label of the given function and creates it if it does not exist yet.
eth::AssemblyItem functionEntryLabel(Declaration const& _declaration);
evmasm::AssemblyItem functionEntryLabel(Declaration const& _declaration);
/// @returns the entry label of the given function. Might return an AssemblyItem of type
/// UndefinedItem if it does not exist yet.
eth::AssemblyItem functionEntryLabelIfExists(Declaration const& _declaration) const;
evmasm::AssemblyItem functionEntryLabelIfExists(Declaration const& _declaration) const;
/// @returns the entry label of the given function and takes overrides into account.
FunctionDefinition const& resolveVirtualFunction(FunctionDefinition const& _function);
/// @returns the function that overrides the given declaration from the most derived class just
@@ -126,7 +125,7 @@ public:
/// list of low-level-functions to be generated, unless it already exists.
/// Note that the generator should not assume that objects are still alive when it is called,
/// unless they are guaranteed to be alive for the whole run of the compiler (AST nodes, for example).
eth::AssemblyItem lowLevelFunctionTag(
evmasm::AssemblyItem lowLevelFunctionTag(
std::string const& _name,
unsigned _inArgs,
unsigned _outArgs,
@@ -149,13 +148,13 @@ public:
std::pair<u256, unsigned> storageLocationOfVariable(Declaration const& _declaration) const;
/// Appends a JUMPI instruction to a new tag and @returns the tag
eth::AssemblyItem appendConditionalJump() { return m_asm->appendJumpI().tag(); }
evmasm::AssemblyItem appendConditionalJump() { return m_asm->appendJumpI().tag(); }
/// Appends a JUMPI instruction to @a _tag
CompilerContext& appendConditionalJumpTo(eth::AssemblyItem const& _tag) { m_asm->appendJumpI(_tag); return *this; }
CompilerContext& appendConditionalJumpTo(evmasm::AssemblyItem const& _tag) { m_asm->appendJumpI(_tag); return *this; }
/// Appends a JUMP to a new tag and @returns the tag
eth::AssemblyItem appendJumpToNew() { return m_asm->appendJump().tag(); }
evmasm::AssemblyItem appendJumpToNew() { return m_asm->appendJump().tag(); }
/// Appends a JUMP to a tag already on the stack
CompilerContext& appendJump(eth::AssemblyItem::JumpType _jumpType = eth::AssemblyItem::JumpType::Ordinary);
CompilerContext& appendJump(evmasm::AssemblyItem::JumpType _jumpType = evmasm::AssemblyItem::JumpType::Ordinary);
/// Appends an INVALID instruction
CompilerContext& appendInvalid();
/// Appends a conditional INVALID instruction
@@ -169,18 +168,18 @@ public:
CompilerContext& appendConditionalRevert(bool _forwardReturnData = false);
/// Appends a JUMP to a specific tag
CompilerContext& appendJumpTo(
eth::AssemblyItem const& _tag,
eth::AssemblyItem::JumpType _jumpType = eth::AssemblyItem::JumpType::Ordinary
evmasm::AssemblyItem const& _tag,
evmasm::AssemblyItem::JumpType _jumpType = evmasm::AssemblyItem::JumpType::Ordinary
) { *m_asm << _tag.pushTag(); return appendJump(_jumpType); }
/// Appends pushing of a new tag and @returns the new tag.
eth::AssemblyItem pushNewTag() { return m_asm->append(m_asm->newPushTag()).tag(); }
evmasm::AssemblyItem pushNewTag() { return m_asm->append(m_asm->newPushTag()).tag(); }
/// @returns a new tag without pushing any opcodes or data
eth::AssemblyItem newTag() { return m_asm->newTag(); }
evmasm::AssemblyItem newTag() { return m_asm->newTag(); }
/// @returns a new tag identified by name.
eth::AssemblyItem namedTag(std::string const& _name) { return m_asm->namedTag(_name); }
evmasm::AssemblyItem namedTag(std::string const& _name) { return m_asm->namedTag(_name); }
/// Adds a subroutine to the code (in the data section) and pushes its size (via a tag)
/// on the stack. @returns the pushsub assembly item.
eth::AssemblyItem addSubroutine(eth::AssemblyPointer const& _assembly) { return m_asm->appendSubroutine(_assembly); }
evmasm::AssemblyItem addSubroutine(evmasm::AssemblyPointer const& _assembly) { return m_asm->appendSubroutine(_assembly); }
/// Pushes the size of the subroutine.
void pushSubroutineSize(size_t _subRoutine) { m_asm->pushSubroutineSize(_subRoutine); }
/// Pushes the offset of the subroutine.
@@ -188,12 +187,12 @@ public:
/// Pushes the size of the final program
void appendProgramSize() { m_asm->appendProgramSize(); }
/// Adds data to the data section, pushes a reference to the stack
eth::AssemblyItem appendData(bytes const& _data) { return m_asm->append(_data); }
evmasm::AssemblyItem appendData(bytes const& _data) { return m_asm->append(_data); }
/// Appends the address (virtual, will be filled in by linker) of a library.
void appendLibraryAddress(std::string const& _identifier) { m_asm->appendLibraryAddress(_identifier); }
/// Appends a zero-address that can be replaced by something else at deploy time (if the
/// position in bytecode is known).
void appendDeployTimeAddress() { m_asm->append(eth::PushDeployTimeAddress); }
void appendDeployTimeAddress() { m_asm->append(evmasm::PushDeployTimeAddress); }
/// Resets the stack of visited nodes with a new stack having only @c _node
void resetVisitedNodes(ASTNode const* _node);
/// Pops the stack of visited nodes
@@ -202,8 +201,8 @@ public:
void pushVisitedNodes(ASTNode const* _node) { m_visitedNodes.push(_node); updateSourceLocation(); }
/// Append elements to the current instruction list and adjust @a m_stackOffset.
CompilerContext& operator<<(eth::AssemblyItem const& _item) { m_asm->append(_item); return *this; }
CompilerContext& operator<<(dev::eth::Instruction _instruction) { m_asm->append(_instruction); return *this; }
CompilerContext& operator<<(evmasm::AssemblyItem const& _item) { m_asm->append(_item); return *this; }
CompilerContext& operator<<(evmasm::Instruction _instruction) { m_asm->append(_instruction); return *this; }
CompilerContext& operator<<(u256 const& _value) { m_asm->append(_value); return *this; }
CompilerContext& operator<<(bytes const& _data) { m_asm->append(_data); return *this; }
@@ -232,10 +231,10 @@ public:
size_t runtimeSub() const { return m_runtimeSub; }
/// @returns a const reference to the underlying assembly.
eth::Assembly const& assembly() const { return *m_asm; }
evmasm::Assembly const& assembly() const { return *m_asm; }
/// @returns a shared pointer to the assembly.
/// Should be avoided except when adding sub-assemblies.
std::shared_ptr<eth::Assembly> assemblyPtr() const { return m_asm; }
std::shared_ptr<evmasm::Assembly> assemblyPtr() const { return m_asm; }
/// @arg _sourceCodes is the map of input files to source code strings
std::string assemblyString(StringMap const& _sourceCodes = StringMap()) const
@@ -249,8 +248,8 @@ public:
return m_asm->assemblyJSON(_sourceCodes);
}
eth::LinkerObject const& assembledObject() const { return m_asm->assemble(); }
eth::LinkerObject const& assembledRuntimeObject(size_t _subIndex) const { return m_asm->sub(_subIndex).assemble(); }
evmasm::LinkerObject const& assembledObject() const { return m_asm->assemble(); }
evmasm::LinkerObject const& assembledRuntimeObject(size_t _subIndex) const { return m_asm->sub(_subIndex).assemble(); }
/**
* Helper class to pop the visited nodes stack when a scope closes
@@ -276,7 +275,7 @@ private:
/// Updates source location set in the assembly.
void updateSourceLocation();
eth::Assembly::OptimiserSettings translateOptimiserSettings(OptimiserSettings const& _settings);
evmasm::Assembly::OptimiserSettings translateOptimiserSettings(OptimiserSettings const& _settings);
/**
* Helper class that manages function labels and ensures that referenced functions are
@@ -286,10 +285,10 @@ private:
{
/// @returns the entry label of the given function and creates it if it does not exist yet.
/// @param _context compiler context used to create a new tag if needed
eth::AssemblyItem entryLabel(Declaration const& _declaration, CompilerContext& _context);
evmasm::AssemblyItem entryLabel(Declaration const& _declaration, CompilerContext& _context);
/// @returns the entry label of the given function. Might return an AssemblyItem of type
/// UndefinedItem if it does not exist yet.
eth::AssemblyItem entryLabelIfExists(Declaration const& _declaration) const;
evmasm::AssemblyItem entryLabelIfExists(Declaration const& _declaration) const;
/// @returns the next function in the queue of functions that are still to be compiled
/// (i.e. that were referenced during compilation but where we did not yet generate code for).
@@ -301,7 +300,7 @@ private:
void startFunction(Declaration const& _function);
/// Labels pointing to the entry points of functions.
std::map<Declaration const*, eth::AssemblyItem> m_entryLabels;
std::map<Declaration const*, evmasm::AssemblyItem> m_entryLabels;
/// Set of functions for which we did not yet generate code.
std::set<Declaration const*> m_alreadyCompiledFunctions;
/// Queue of functions that still need to be compiled (important to be a queue to maintain
@@ -310,7 +309,7 @@ private:
mutable std::queue<Declaration const*> m_functionsToCompile;
} m_functionCompilationQueue;
eth::AssemblyPointer m_asm;
evmasm::AssemblyPointer m_asm;
/// Version of the EVM to compile against.
langutil::EVMVersion m_evmVersion;
/// Activated experimental features.
@@ -333,7 +332,7 @@ private:
/// The index of the runtime subroutine.
size_t m_runtimeSub = -1;
/// An index of low-level function labels by name.
std::map<std::string, eth::AssemblyItem> m_lowLevelFunctions;
std::map<std::string, evmasm::AssemblyItem> m_lowLevelFunctions;
/// Container for ABI functions to be generated.
ABIFunctions m_abiFunctions;
/// The queue of low-level functions to generate.
@@ -341,4 +340,3 @@ private:
};
}
}
+12 -8
View File
@@ -31,10 +31,14 @@
#include <libdevcore/Whiskers.h>
using namespace std;
using namespace langutil;
using namespace dev;
using namespace dev::eth;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::frontend;
using namespace solidity::langutil;
using solidity::util::Whiskers;
using solidity::util::h256;
using solidity::util::toCompactHexWithPrefix;
unsigned const CompilerUtils::dataStartOffset = 4;
size_t const CompilerUtils::freeMemoryPointer = 64;
@@ -86,7 +90,7 @@ void CompilerUtils::revertWithStringData(Type const& _argumentType)
{
solAssert(_argumentType.isImplicitlyConvertibleTo(*TypeProvider::fromElementaryTypeName("string memory")), "");
fetchFreeMemoryPointer();
m_context << (u256(FixedHash<4>::Arith(FixedHash<4>(dev::keccak256("Error(string)")))) << (256 - 32));
m_context << (u256(util::FixedHash<4>::Arith(util::FixedHash<4>(util::keccak256("Error(string)")))) << (256 - 32));
m_context << Instruction::DUP2 << Instruction::MSTORE;
m_context << u256(4) << Instruction::ADD;
// Stack: <string data> <mem pos of encoding start>
@@ -1263,7 +1267,7 @@ void CompilerUtils::moveToStackVariable(VariableDeclaration const& _variable)
BOOST_THROW_EXCEPTION(
CompilerError() <<
errinfo_sourceLocation(_variable.location()) <<
errinfo_comment("Stack too deep, try removing local variables.")
util::errinfo_comment("Stack too deep, try removing local variables.")
);
for (unsigned i = 0; i < size; ++i)
m_context << swapInstruction(stackPosition - size + 1) << Instruction::POP;
@@ -1316,7 +1320,7 @@ void CompilerUtils::popStackSlots(size_t _amount)
m_context << Instruction::POP;
}
void CompilerUtils::popAndJump(unsigned _toHeight, eth::AssemblyItem const& _jumpTo)
void CompilerUtils::popAndJump(unsigned _toHeight, evmasm::AssemblyItem const& _jumpTo)
{
solAssert(m_context.stackHeight() >= _toHeight, "");
unsigned amount = m_context.stackHeight() - _toHeight;
@@ -1349,7 +1353,7 @@ void CompilerUtils::copyContractCodeToMemory(ContractDefinition const& contract,
[&contract, _creation](CompilerContext& _context)
{
// copy the contract's code into memory
shared_ptr<eth::Assembly> assembly =
shared_ptr<evmasm::Assembly> assembly =
_creation ?
_context.compiledContract(contract) :
_context.compiledContractRuntime(contract);
+2 -4
View File
@@ -27,8 +27,7 @@
#include <libsolidity/codegen/CompilerContext.h>
#include <libsolidity/codegen/CompilerContext.h>
namespace dev {
namespace solidity {
namespace solidity::frontend {
class Type; // forward
@@ -266,7 +265,7 @@ public:
/// Pops slots from the stack such that its height is _toHeight.
/// Adds jump to _jumpTo.
/// Readjusts the stack offset to the original value.
void popAndJump(unsigned _toHeight, eth::AssemblyItem const& _jumpTo);
void popAndJump(unsigned _toHeight, evmasm::AssemblyItem const& _jumpTo);
template <class T>
static unsigned sizeOnStack(std::vector<T> const& _variables);
@@ -326,4 +325,3 @@ unsigned CompilerUtils::sizeOnStack(std::vector<T> const& _variables)
}
}
}
+34 -30
View File
@@ -41,10 +41,14 @@
#include <algorithm>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::eth;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::frontend;
using namespace solidity::langutil;
using solidity::util::FixedHash;
using solidity::util::h256;
using solidity::util::errinfo_comment;
namespace
{
@@ -158,7 +162,7 @@ size_t ContractCompiler::packIntoContractCreator(ContractDefinition const& _cont
// We jump to the deploy routine because we first have to append all missing functions,
// which can cause further functions to be added to the runtime context.
eth::AssemblyItem deployRoutine = m_context.appendJumpToNew();
evmasm::AssemblyItem deployRoutine = m_context.appendJumpToNew();
// We have to include copies of functions in the construction time and runtime context
// because of absolute jumps.
@@ -268,9 +272,9 @@ void ContractCompiler::appendDelegatecallCheck()
}
void ContractCompiler::appendInternalSelector(
map<FixedHash<4>, eth::AssemblyItem const> const& _entryPoints,
map<FixedHash<4>, evmasm::AssemblyItem const> const& _entryPoints,
vector<FixedHash<4>> const& _ids,
eth::AssemblyItem const& _notFoundTag,
evmasm::AssemblyItem const& _notFoundTag,
size_t _runs
)
{
@@ -301,17 +305,17 @@ void ContractCompiler::appendInternalSelector(
bool split = false;
if (_ids.size() <= 4)
split = false;
else if (_runs > (17 * eth::GasCosts::createDataGas) / 6)
else if (_runs > (17 * evmasm::GasCosts::createDataGas) / 6)
split = true;
else
split = (_runs * 6 * (_ids.size() - 4) > 17 * eth::GasCosts::createDataGas);
split = (_runs * 6 * (_ids.size() - 4) > 17 * evmasm::GasCosts::createDataGas);
if (split)
{
size_t pivotIndex = _ids.size() / 2;
FixedHash<4> pivot{_ids.at(pivotIndex)};
m_context << dupInstruction(1) << u256(FixedHash<4>::Arith(pivot)) << Instruction::GT;
eth::AssemblyItem lessTag{m_context.appendConditionalJump()};
evmasm::AssemblyItem lessTag{m_context.appendConditionalJump()};
// Here, we have funid >= pivot
vector<FixedHash<4>> larger{_ids.begin() + pivotIndex, _ids.end()};
appendInternalSelector(_entryPoints, larger, _notFoundTag, _runs);
@@ -356,7 +360,7 @@ bool hasPayableFunctions(ContractDefinition const& _contract)
void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contract)
{
map<FixedHash<4>, FunctionTypePointer> interfaceFunctions = _contract.interfaceFunctions();
map<FixedHash<4>, eth::AssemblyItem const> callDataUnpackerEntryPoints;
map<FixedHash<4>, evmasm::AssemblyItem const> callDataUnpackerEntryPoints;
if (_contract.isLibrary())
{
@@ -376,10 +380,10 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac
needToAddCallvalueCheck = false;
}
eth::AssemblyItem notFoundOrReceiveEther = m_context.newTag();
evmasm::AssemblyItem notFoundOrReceiveEther = m_context.newTag();
// If there is neither a fallback nor a receive ether function, we only need one label to jump to, which
// always reverts.
eth::AssemblyItem notFound = (!fallback && !etherReceiver) ? notFoundOrReceiveEther : m_context.newTag();
evmasm::AssemblyItem notFound = (!fallback && !etherReceiver) ? notFoundOrReceiveEther : m_context.newTag();
// directly jump to fallback or ether receiver if the data is too short to contain a function selector
// also guards against short data
@@ -462,7 +466,7 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac
appendCallValueCheck();
// Return tag is used to jump out of the function.
eth::AssemblyItem returnTag = m_context.pushNewTag();
evmasm::AssemblyItem returnTag = m_context.pushNewTag();
if (!functionType->parameterTypes().empty())
{
// Parameter for calldataUnpacker
@@ -472,7 +476,7 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac
}
m_context.appendJumpTo(
m_context.functionEntryLabel(functionType->declaration()),
eth::AssemblyItem::JumpType::IntoFunction
evmasm::AssemblyItem::JumpType::IntoFunction
);
m_context << returnTag;
// Return tag and input parameters get consumed.
@@ -619,7 +623,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
{
solAssert(m_context.numberOfLocalVariables() == 0, "");
if (!_function.isFallback() && !_function.isReceive())
m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
m_context.appendJump(evmasm::AssemblyItem::JumpType::OutOfFunction);
}
return false;
@@ -809,14 +813,14 @@ bool ContractCompiler::visit(TryStatement const& _tryStatement)
int const returnSize = static_cast<int>(_tryStatement.externalCall().annotation().type->sizeOnStack());
// Stack: [ return values] <success flag>
eth::AssemblyItem successTag = m_context.appendConditionalJump();
evmasm::AssemblyItem successTag = m_context.appendConditionalJump();
// Catch case.
m_context.adjustStackOffset(-returnSize);
handleCatch(_tryStatement.clauses());
eth::AssemblyItem endTag = m_context.appendJumpToNew();
evmasm::AssemblyItem endTag = m_context.appendJumpToNew();
m_context << successTag;
m_context.adjustStackOffset(returnSize);
@@ -860,8 +864,8 @@ void ContractCompiler::handleCatch(vector<ASTPointer<TryCatchClause>> const& _ca
solAssert(_catchClauses.size() == size_t(1 + (structured ? 1 : 0) + (fallback ? 1 : 0)), "");
eth::AssemblyItem endTag = m_context.newTag();
eth::AssemblyItem fallbackTag = m_context.newTag();
evmasm::AssemblyItem endTag = m_context.newTag();
evmasm::AssemblyItem fallbackTag = m_context.newTag();
if (structured)
{
solAssert(
@@ -873,13 +877,13 @@ void ContractCompiler::handleCatch(vector<ASTPointer<TryCatchClause>> const& _ca
);
solAssert(m_context.evmVersion().supportsReturndata(), "");
string errorHash = FixedHash<4>(dev::keccak256("Error(string)")).hex();
string errorHash = FixedHash<4>(util::keccak256("Error(string)")).hex();
// Try to decode the error message.
// If this fails, leaves 0 on the stack, otherwise the pointer to the data string.
m_context << u256(0);
m_context.appendInlineAssembly(
Whiskers(R"({
util::Whiskers(R"({
data := mload(0x40)
mstore(data, 0)
for {} 1 {} {
@@ -983,8 +987,8 @@ bool ContractCompiler::visit(IfStatement const& _ifStatement)
CompilerContext::LocationSetter locationSetter(m_context, _ifStatement);
compileExpression(_ifStatement.condition());
m_context << Instruction::ISZERO;
eth::AssemblyItem falseTag = m_context.appendConditionalJump();
eth::AssemblyItem endTag = falseTag;
evmasm::AssemblyItem falseTag = m_context.appendConditionalJump();
evmasm::AssemblyItem endTag = falseTag;
_ifStatement.trueStatement().accept(*this);
if (_ifStatement.falseStatement())
{
@@ -1003,15 +1007,15 @@ bool ContractCompiler::visit(WhileStatement const& _whileStatement)
StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, _whileStatement);
eth::AssemblyItem loopStart = m_context.newTag();
eth::AssemblyItem loopEnd = m_context.newTag();
evmasm::AssemblyItem loopStart = m_context.newTag();
evmasm::AssemblyItem loopEnd = m_context.newTag();
m_breakTags.emplace_back(loopEnd, m_context.stackHeight());
m_context << loopStart;
if (_whileStatement.isDoWhile())
{
eth::AssemblyItem condition = m_context.newTag();
evmasm::AssemblyItem condition = m_context.newTag();
m_continueTags.emplace_back(condition, m_context.stackHeight());
_whileStatement.body().accept(*this);
@@ -1045,9 +1049,9 @@ bool ContractCompiler::visit(ForStatement const& _forStatement)
{
StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, _forStatement);
eth::AssemblyItem loopStart = m_context.newTag();
eth::AssemblyItem loopEnd = m_context.newTag();
eth::AssemblyItem loopNext = m_context.newTag();
evmasm::AssemblyItem loopStart = m_context.newTag();
evmasm::AssemblyItem loopEnd = m_context.newTag();
evmasm::AssemblyItem loopNext = m_context.newTag();
storeStackHeight(&_forStatement);
+8 -10
View File
@@ -28,10 +28,9 @@
#include <libevmasm/Assembly.h>
#include <functional>
#include <ostream>
#include <map>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -92,9 +91,9 @@ private:
/// Appends the function selector. Is called recursively to create a binary search tree.
/// @a _runs the number of intended executions of the contract to tune the split point.
void appendInternalSelector(
std::map<FixedHash<4>, eth::AssemblyItem const> const& _entryPoints,
std::vector<FixedHash<4>> const& _ids,
eth::AssemblyItem const& _notFoundTag,
std::map<util::FixedHash<4>, evmasm::AssemblyItem const> const& _entryPoints,
std::vector<util::FixedHash<4>> const& _ids,
evmasm::AssemblyItem const& _notFoundTag,
size_t _runs
);
void appendFunctionSelector(ContractDefinition const& _contract);
@@ -146,12 +145,12 @@ private:
ContractCompiler* m_runtimeCompiler = nullptr;
CompilerContext& m_context;
/// Tag to jump to for a "break" statement and the stack height after freeing the local loop variables.
std::vector<std::pair<eth::AssemblyItem, unsigned>> m_breakTags;
std::vector<std::pair<evmasm::AssemblyItem, unsigned>> m_breakTags;
/// Tag to jump to for a "continue" statement and the stack height after freeing the local loop variables.
std::vector<std::pair<eth::AssemblyItem, unsigned>> m_continueTags;
std::vector<std::pair<evmasm::AssemblyItem, unsigned>> m_continueTags;
/// Tag to jump to for a "return" statement and the stack height after freeing the local function or modifier variables.
/// Needs to be stacked because of modifiers.
std::vector<std::pair<eth::AssemblyItem, unsigned>> m_returnTags;
std::vector<std::pair<evmasm::AssemblyItem, unsigned>> m_returnTags;
unsigned m_modifierDepth = 0;
FunctionDefinition const* m_currentFunction = nullptr;
@@ -163,4 +162,3 @@ private:
};
}
}
+20 -19
View File
@@ -39,10 +39,11 @@
#include <utility>
using namespace std;
using namespace langutil;
using namespace dev;
using namespace dev::eth;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::frontend;
using namespace solidity::langutil;
using namespace solidity::util;
void ExpressionCompiler::compile(Expression const& _expression)
@@ -82,7 +83,7 @@ void ExpressionCompiler::appendConstStateVariableAccessor(VariableDeclaration co
// append return
m_context << dupInstruction(_varDecl.annotation().type->sizeOnStack() + 1);
m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
m_context.appendJump(evmasm::AssemblyItem::JumpType::OutOfFunction);
}
void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& _varDecl)
@@ -216,16 +217,16 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
errinfo_comment("Stack too deep.")
);
m_context << dupInstruction(retSizeOnStack + 1);
m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
m_context.appendJump(evmasm::AssemblyItem::JumpType::OutOfFunction);
}
bool ExpressionCompiler::visit(Conditional const& _condition)
{
CompilerContext::LocationSetter locationSetter(m_context, _condition);
_condition.condition().accept(*this);
eth::AssemblyItem trueTag = m_context.appendConditionalJump();
evmasm::AssemblyItem trueTag = m_context.appendConditionalJump();
acceptAndConvert(_condition.falseExpression(), *_condition.annotation().type);
eth::AssemblyItem endTag = m_context.appendJumpToNew();
evmasm::AssemblyItem endTag = m_context.appendJumpToNew();
m_context << trueTag;
int offset = _condition.annotation().type->sizeOnStack();
m_context.adjustStackOffset(-offset);
@@ -554,7 +555,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
// Calling convention: Caller pushes return address and arguments
// Callee removes them and pushes return values
eth::AssemblyItem returnLabel = m_context.pushNewTag();
evmasm::AssemblyItem returnLabel = m_context.pushNewTag();
for (unsigned i = 0; i < arguments.size(); ++i)
acceptAndConvert(*arguments[i], *function.parameterTypes()[i]);
@@ -593,7 +594,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
// Extract the runtime part.
m_context << ((u256(1) << 32) - 1) << Instruction::AND;
m_context.appendJump(eth::AssemblyItem::JumpType::IntoFunction);
m_context.appendJump(evmasm::AssemblyItem::JumpType::IntoFunction);
m_context << returnLabel;
unsigned returnParametersSize = CompilerUtils::sizeOnStack(function.returnParameterTypes());
@@ -683,7 +684,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
_functionCall.expression().accept(*this);
// Provide the gas stipend manually at first because we may send zero ether.
// Will be zeroed if we send more than zero ether.
m_context << u256(eth::GasCosts::callStipend);
m_context << u256(evmasm::GasCosts::callStipend);
acceptAndConvert(*arguments.front(), *function.parameterTypes().front(), true);
// gas <- gas * !value
m_context << Instruction::SWAP1 << Instruction::DUP2;
@@ -819,7 +820,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
}
if (!event.isAnonymous())
{
m_context << u256(h256::Arith(dev::keccak256(function.externalSignature())));
m_context << u256(h256::Arith(keccak256(function.externalSignature())));
++numIndexed;
}
solAssert(numIndexed <= 4, "Too many indexed arguments.");
@@ -1109,7 +1110,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
// hash the signature
if (auto const* stringType = dynamic_cast<StringLiteralType const*>(selectorType))
{
FixedHash<4> hash(dev::keccak256(stringType->value()));
FixedHash<4> hash(keccak256(stringType->value()));
m_context << (u256(FixedHash<4>::Arith(hash)) << (256 - 32));
dataOnStack = TypeProvider::fixedBytes(4);
}
@@ -1836,7 +1837,7 @@ void ExpressionCompiler::appendAndOrOperatorCode(BinaryOperation const& _binaryO
m_context << Instruction::DUP1;
if (c_op == Token::And)
m_context << Instruction::ISZERO;
eth::AssemblyItem endLabel = m_context.appendConditionalJump();
evmasm::AssemblyItem endLabel = m_context.appendConditionalJump();
m_context << Instruction::POP;
_binaryOperation.rightExpression().accept(*this);
m_context << endLabel;
@@ -2234,11 +2235,11 @@ void ExpressionCompiler::appendExternalFunctionCall(
{
// send all gas except the amount needed to execute "SUB" and "CALL"
// @todo this retains too much gas for now, needs to be fine-tuned.
u256 gasNeededByCaller = eth::GasCosts::callGas(m_context.evmVersion()) + 10;
u256 gasNeededByCaller = evmasm::GasCosts::callGas(m_context.evmVersion()) + 10;
if (_functionType.valueSet())
gasNeededByCaller += eth::GasCosts::callValueTransferGas;
gasNeededByCaller += evmasm::GasCosts::callValueTransferGas;
if (!existenceChecked)
gasNeededByCaller += eth::GasCosts::callNewAccountGas; // we never know
gasNeededByCaller += evmasm::GasCosts::callNewAccountGas; // we never know
m_context << gasNeededByCaller << Instruction::GAS << Instruction::SUB;
}
// Order is important here, STATICCALL might overlap with DELEGATECALL.
@@ -2255,7 +2256,7 @@ void ExpressionCompiler::appendExternalFunctionCall(
(_functionType.gasSet() ? 1 : 0) +
(!_functionType.isBareCall() ? 1 : 0);
eth::AssemblyItem endTag = m_context.newTag();
evmasm::AssemblyItem endTag = m_context.newTag();
if (!returnSuccessConditionAndReturndata && !_tryCall)
{
@@ -2326,7 +2327,7 @@ void ExpressionCompiler::appendExternalFunctionCall(
solAssert(retSize > 0, "");
// Always use the actual return length, and not our calculated expected length, if returndatacopy is supported.
// This ensures it can catch badly formatted input from external calls.
m_context << (haveReturndatacopy ? eth::AssemblyItem(Instruction::RETURNDATASIZE) : u256(retSize));
m_context << (haveReturndatacopy ? evmasm::AssemblyItem(Instruction::RETURNDATASIZE) : u256(retSize));
// Stack: return_data_start return_data_size
if (needToUpdateFreeMemoryPtr)
m_context.appendInlineAssembly(R"({
+3 -4
View File
@@ -34,12 +34,12 @@
#include <functional>
#include <memory>
namespace dev {
namespace eth
namespace solidity::evmasm
{
class AssemblyItem; // forward
}
namespace solidity {
namespace solidity::frontend {
// forward declarations
class CompilerContext;
@@ -157,4 +157,3 @@ void ExpressionCompiler::setLValue(Expression const& _expression, _Arguments con
}
}
}
+5 -4
View File
@@ -28,10 +28,11 @@
#include <libevmasm/Instruction.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace dev::solidity;
using namespace langutil;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::frontend;
using namespace solidity::langutil;
using namespace solidity::util;
StackVariable::StackVariable(CompilerContext& _compilerContext, VariableDeclaration const& _declaration):
+1 -4
View File
@@ -27,9 +27,7 @@
#include <memory>
#include <vector>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class Declaration;
@@ -197,4 +195,3 @@ private:
};
}
}
@@ -27,8 +27,8 @@
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
string MultiUseYulFunctionCollector::requestedFunctions()
{
@@ -25,9 +25,7 @@
#include <map>
#include <string>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@@ -53,4 +51,3 @@ private:
};
}
}
+4 -3
View File
@@ -32,8 +32,9 @@
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
string YulUtilFunctions::combineExternalFunctionIdFunction()
{
@@ -130,7 +131,7 @@ string YulUtilFunctions::requireOrAssertFunction(bool _assert, Type const* _mess
int const byteSize = 8;
u256 const errorHash =
u256(FixedHash<hashHeaderSize>::Arith(
FixedHash<hashHeaderSize>(dev::keccak256("Error(string)"))
FixedHash<hashHeaderSize>(keccak256("Error(string)"))
)) << (256 - hashHeaderSize * byteSize);
string const encodeFunc = ABIFunctions(m_evmVersion, m_functionCollector)
+1 -4
View File
@@ -28,9 +28,7 @@
#include <string>
#include <vector>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class Type;
@@ -295,4 +293,3 @@ private:
};
}
}
@@ -26,9 +26,10 @@
#include <libdevcore/Whiskers.h>
#include <libdevcore/StringUtils.h>
using namespace dev;
using namespace dev::solidity;
using namespace std;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
string IRGenerationContext::addLocalVariable(VariableDeclaration const& _varDecl)
{
+1 -4
View File
@@ -32,9 +32,7 @@
#include <memory>
#include <vector>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class ContractDefinition;
@@ -107,4 +105,3 @@ private:
};
}
}
+3 -2
View File
@@ -44,8 +44,9 @@
#include <sstream>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
pair<string, string> IRGenerator::run(ContractDefinition const& _contract)
{
+1 -4
View File
@@ -29,9 +29,7 @@
#include <liblangutil/EVMVersion.h>
#include <string>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class SourceUnit;
@@ -80,4 +78,3 @@ private:
};
}
}
@@ -35,14 +35,14 @@
#include <libyul/Dialect.h>
#include <libyul/optimiser/ASTCopier.h>
#include <libdevcore/Whiskers.h>
#include <libdevcore/StringUtils.h>
#include <libdevcore/Whiskers.h>
#include <libdevcore/Keccak256.h>
#include <libsolutil/Whiskers.h>
#include <libsolutil/StringUtils.h>
#include <libsolutil/Keccak256.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
namespace
{
@@ -543,7 +543,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
if (!event.isAnonymous())
{
indexedArgs.emplace_back(m_context.newYulVariable());
string signature = formatNumber(u256(h256::Arith(dev::keccak256(functionType->externalSignature()))));
string signature = formatNumber(u256(h256::Arith(keccak256(functionType->externalSignature()))));
m_code << "let " << indexedArgs.back() << " := " << signature << "\n";
}
for (size_t i = 0; i < event.parameters().size(); ++i)
@@ -1220,11 +1220,11 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
{
// send all gas except the amount needed to execute "SUB" and "CALL"
// @todo this retains too much gas for now, needs to be fine-tuned.
u256 gasNeededByCaller = eth::GasCosts::callGas(m_context.evmVersion()) + 10;
u256 gasNeededByCaller = evmasm::GasCosts::callGas(m_context.evmVersion()) + 10;
if (funType.valueSet())
gasNeededByCaller += eth::GasCosts::callValueTransferGas;
gasNeededByCaller += evmasm::GasCosts::callValueTransferGas;
if (!checkExistence)
gasNeededByCaller += eth::GasCosts::callNewAccountGas; // we never know
gasNeededByCaller += evmasm::GasCosts::callNewAccountGas; // we never know
templ("gas", "sub(gas(), " + formatNumber(gasNeededByCaller) + ")");
}
// Order is important here, STATICCALL might overlap with DELEGATECALL.
@@ -23,9 +23,7 @@
#include <libsolidity/ast/ASTVisitor.h>
#include <libsolidity/codegen/ir/IRLValue.h>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class IRGenerationContext;
@@ -114,4 +112,3 @@ private:
};
}
}
+3 -3
View File
@@ -28,8 +28,8 @@
#include <libdevcore/Whiskers.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
IRLocalVariable::IRLocalVariable(
IRGenerationContext& _context,
@@ -68,7 +68,7 @@ IRStorageItem::IRStorageItem(
std::pair<u256, unsigned> slot_offset
):
IRLValue(std::move(_utils), &_type),
m_slot(toCompactHexWithPrefix(slot_offset.first)),
m_slot(util::toCompactHexWithPrefix(slot_offset.first)),
m_offset(slot_offset.second)
{
}
+1 -4
View File
@@ -28,9 +28,7 @@
#include <ostream>
#include <boost/variant.hpp>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class VariableDeclaration;
@@ -129,4 +127,3 @@ private:
};
}
}
+4 -3
View File
@@ -23,9 +23,10 @@
#include <boost/algorithm/string/replace.hpp>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
using namespace solidity::frontend;
BMC::BMC(
smt::EncodingContext& _context,
+4 -5
View File
@@ -39,15 +39,15 @@
#include <string>
#include <vector>
namespace langutil
using solidity::util::h256;
namespace solidity::langutil
{
class ErrorReporter;
struct SourceLocation;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class BMC: public SMTEncoder
@@ -186,4 +186,3 @@ private:
};
}
}
+4 -4
View File
@@ -28,14 +28,14 @@
#include <libsolidity/ast/TypeProvider.h>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
CHC::CHC(
smt::EncodingContext& _context,
ErrorReporter& _errorReporter,
map<h256, string> const& _smtlib2Responses,
map<util::h256, string> const& _smtlib2Responses,
ReadCallback::Callback const& _smtCallback,
[[maybe_unused]] smt::SMTSolverChoice _enabledSolvers
):
+2 -5
View File
@@ -38,9 +38,7 @@
#include <set>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class CHC: public SMTEncoder
@@ -49,7 +47,7 @@ public:
CHC(
smt::EncodingContext& _context,
langutil::ErrorReporter& _errorReporter,
std::map<h256, std::string> const& _smtlib2Responses,
std::map<util::h256, std::string> const& _smtlib2Responses,
ReadCallback::Callback const& _smtCallback,
smt::SMTSolverChoice _enabledSolvers
);
@@ -217,4 +215,3 @@ private:
};
}
}
+5 -4
View File
@@ -30,9 +30,10 @@
#include <stdexcept>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace dev::solidity::smt;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
using namespace solidity::frontend::smt;
CHCSmtLib2Interface::CHCSmtLib2Interface(
map<h256, string> const& _queryResponses,
@@ -153,7 +154,7 @@ void CHCSmtLib2Interface::write(string _data)
string CHCSmtLib2Interface::querySolver(string const& _input)
{
h256 inputHash = dev::keccak256(_input);
util::h256 inputHash = util::keccak256(_input);
if (m_queryResponses.count(inputHash))
return m_queryResponses.at(inputHash);
if (m_smtCallback)
+3 -9
View File
@@ -25,18 +25,14 @@
#include <libsolidity/formal/SMTLib2Interface.h>
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
class CHCSmtLib2Interface: public CHCSolverInterface
{
public:
explicit CHCSmtLib2Interface(
std::map<h256, std::string> const& _queryResponses,
std::map<util::h256, std::string> const& _queryResponses,
ReadCallback::Callback const& _smtCallback
);
@@ -68,12 +64,10 @@ private:
std::string m_accumulatedOutput;
std::set<std::string> m_variables;
std::map<h256, std::string> const& m_queryResponses;
std::map<util::h256, std::string> const& m_queryResponses;
std::vector<std::string> m_unhandledQueries;
ReadCallback::Callback m_smtCallback;
};
}
}
}
+1 -7
View File
@@ -23,11 +23,7 @@
#include <libsolidity/formal/SolverInterface.h>
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
class CHCSolverInterface
@@ -52,5 +48,3 @@ public:
};
}
}
}
+3 -2
View File
@@ -21,8 +21,9 @@
#include <libdevcore/CommonIO.h>
using namespace std;
using namespace dev;
using namespace dev::solidity::smt;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend::smt;
CVC4Interface::CVC4Interface():
m_solver(&m_context)
+1 -7
View File
@@ -33,11 +33,7 @@
#undef _GLIBCXX_PERMIT_BACKWARD_HASH
#endif
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
class CVC4Interface: public SolverInterface, public boost::noncopyable
@@ -72,5 +68,3 @@ private:
};
}
}
}
+17 -16
View File
@@ -20,8 +20,9 @@
#include <libsolidity/formal/SymbolicTypes.h>
using namespace std;
using namespace dev;
using namespace dev::solidity::smt;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend::smt;
EncodingContext::EncodingContext():
m_thisAddress(make_unique<SymbolicAddressVariable>("this", *this))
@@ -51,13 +52,13 @@ void EncodingContext::clear()
/// Variables.
shared_ptr<SymbolicVariable> EncodingContext::variable(solidity::VariableDeclaration const& _varDecl)
shared_ptr<SymbolicVariable> EncodingContext::variable(frontend::VariableDeclaration const& _varDecl)
{
solAssert(knownVariable(_varDecl), "");
return m_variables[&_varDecl];
}
bool EncodingContext::createVariable(solidity::VariableDeclaration const& _varDecl)
bool EncodingContext::createVariable(frontend::VariableDeclaration const& _varDecl)
{
solAssert(!knownVariable(_varDecl), "");
auto const& type = _varDecl.type();
@@ -66,24 +67,24 @@ bool EncodingContext::createVariable(solidity::VariableDeclaration const& _varDe
return result.first;
}
bool EncodingContext::knownVariable(solidity::VariableDeclaration const& _varDecl)
bool EncodingContext::knownVariable(frontend::VariableDeclaration const& _varDecl)
{
return m_variables.count(&_varDecl);
}
void EncodingContext::resetVariable(solidity::VariableDeclaration const& _variable)
void EncodingContext::resetVariable(frontend::VariableDeclaration const& _variable)
{
newValue(_variable);
setUnknownValue(_variable);
}
void EncodingContext::resetVariables(set<solidity::VariableDeclaration const*> const& _variables)
void EncodingContext::resetVariables(set<frontend::VariableDeclaration const*> const& _variables)
{
for (auto const* decl: _variables)
resetVariable(*decl);
}
void EncodingContext::resetVariables(function<bool(solidity::VariableDeclaration const&)> const& _filter)
void EncodingContext::resetVariables(function<bool(frontend::VariableDeclaration const&)> const& _filter)
{
for_each(begin(m_variables), end(m_variables), [&](auto _variable)
{
@@ -94,16 +95,16 @@ void EncodingContext::resetVariables(function<bool(solidity::VariableDeclaration
void EncodingContext::resetAllVariables()
{
resetVariables([&](solidity::VariableDeclaration const&) { return true; });
resetVariables([&](frontend::VariableDeclaration const&) { return true; });
}
Expression EncodingContext::newValue(solidity::VariableDeclaration const& _decl)
Expression EncodingContext::newValue(frontend::VariableDeclaration const& _decl)
{
solAssert(knownVariable(_decl), "");
return m_variables.at(&_decl)->increaseIndex();
}
void EncodingContext::setZeroValue(solidity::VariableDeclaration const& _decl)
void EncodingContext::setZeroValue(frontend::VariableDeclaration const& _decl)
{
solAssert(knownVariable(_decl), "");
setZeroValue(*m_variables.at(&_decl));
@@ -114,7 +115,7 @@ void EncodingContext::setZeroValue(SymbolicVariable& _variable)
setSymbolicZeroValue(_variable, *this);
}
void EncodingContext::setUnknownValue(solidity::VariableDeclaration const& _decl)
void EncodingContext::setUnknownValue(frontend::VariableDeclaration const& _decl)
{
solAssert(knownVariable(_decl), "");
setUnknownValue(*m_variables.at(&_decl));
@@ -127,14 +128,14 @@ void EncodingContext::setUnknownValue(SymbolicVariable& _variable)
/// Expressions
shared_ptr<SymbolicVariable> EncodingContext::expression(solidity::Expression const& _e)
shared_ptr<SymbolicVariable> EncodingContext::expression(frontend::Expression const& _e)
{
if (!knownExpression(_e))
createExpression(_e);
return m_expressions.at(&_e);
}
bool EncodingContext::createExpression(solidity::Expression const& _e, shared_ptr<SymbolicVariable> _symbVar)
bool EncodingContext::createExpression(frontend::Expression const& _e, shared_ptr<SymbolicVariable> _symbVar)
{
solAssert(_e.annotation().type, "");
if (knownExpression(_e))
@@ -155,7 +156,7 @@ bool EncodingContext::createExpression(solidity::Expression const& _e, shared_pt
}
}
bool EncodingContext::knownExpression(solidity::Expression const& _e) const
bool EncodingContext::knownExpression(frontend::Expression const& _e) const
{
return m_expressions.count(&_e);
}
@@ -168,7 +169,7 @@ shared_ptr<SymbolicVariable> EncodingContext::globalSymbol(string const& _name)
return m_globalContext.at(_name);
}
bool EncodingContext::createGlobalSymbol(string const& _name, solidity::Expression const& _expr)
bool EncodingContext::createGlobalSymbol(string const& _name, frontend::Expression const& _expr)
{
solAssert(!knownGlobalSymbol(_name), "");
auto result = newSymbolicVariable(*_expr.annotation().type, _name, *this);
+18 -24
View File
@@ -23,11 +23,7 @@
#include <unordered_map>
#include <set>
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
/**
@@ -67,48 +63,48 @@ public:
/// Variables.
//@{
/// @returns the symbolic representation of a program variable.
std::shared_ptr<SymbolicVariable> variable(solidity::VariableDeclaration const& _varDecl);
std::shared_ptr<SymbolicVariable> variable(frontend::VariableDeclaration const& _varDecl);
/// @returns all symbolic variables.
std::unordered_map<solidity::VariableDeclaration const*, std::shared_ptr<SymbolicVariable>> const& variables() const { return m_variables; }
std::unordered_map<frontend::VariableDeclaration const*, std::shared_ptr<SymbolicVariable>> const& variables() const { return m_variables; }
/// Creates a symbolic variable and
/// @returns true if a variable's type is not supported and is therefore abstract.
bool createVariable(solidity::VariableDeclaration const& _varDecl);
bool createVariable(frontend::VariableDeclaration const& _varDecl);
/// @returns true if variable was created.
bool knownVariable(solidity::VariableDeclaration const& _varDecl);
bool knownVariable(frontend::VariableDeclaration const& _varDecl);
/// Resets a specific variable.
void resetVariable(solidity::VariableDeclaration const& _variable);
void resetVariable(frontend::VariableDeclaration const& _variable);
/// Resets a set of variables.
void resetVariables(std::set<solidity::VariableDeclaration const*> const& _variables);
void resetVariables(std::set<frontend::VariableDeclaration const*> const& _variables);
/// Resets variables according to a predicate.
void resetVariables(std::function<bool(solidity::VariableDeclaration const&)> const& _filter);
void resetVariables(std::function<bool(frontend::VariableDeclaration const&)> const& _filter);
///Resets all variables.
void resetAllVariables();
/// Allocates a new index for the declaration, updates the current
/// index to this value and returns the expression.
Expression newValue(solidity::VariableDeclaration const& _decl);
Expression newValue(frontend::VariableDeclaration const& _decl);
/// Sets the value of the declaration to zero.
void setZeroValue(solidity::VariableDeclaration const& _decl);
void setZeroValue(frontend::VariableDeclaration const& _decl);
void setZeroValue(SymbolicVariable& _variable);
/// Resets the variable to an unknown value (in its range).
void setUnknownValue(solidity::VariableDeclaration const& decl);
void setUnknownValue(frontend::VariableDeclaration const& decl);
void setUnknownValue(SymbolicVariable& _variable);
//@}
/// Expressions.
////@{
/// @returns the symbolic representation of an AST node expression.
std::shared_ptr<SymbolicVariable> expression(solidity::Expression const& _e);
std::shared_ptr<SymbolicVariable> expression(frontend::Expression const& _e);
/// @returns all symbolic expressions.
std::unordered_map<solidity::Expression const*, std::shared_ptr<SymbolicVariable>> const& expressions() const { return m_expressions; }
std::unordered_map<frontend::Expression const*, std::shared_ptr<SymbolicVariable>> const& expressions() const { return m_expressions; }
/// Creates the expression (value can be arbitrary).
/// @returns true if type is not supported.
bool createExpression(solidity::Expression const& _e, std::shared_ptr<SymbolicVariable> _symbExpr = nullptr);
bool createExpression(frontend::Expression const& _e, std::shared_ptr<SymbolicVariable> _symbExpr = nullptr);
/// Checks if expression was created.
bool knownExpression(solidity::Expression const& _e) const;
bool knownExpression(frontend::Expression const& _e) const;
//@}
/// Global variables and functions.
@@ -120,7 +116,7 @@ public:
/// Defines a new global variable or function
/// and @returns true if type was abstracted.
bool createGlobalSymbol(std::string const& _name, solidity::Expression const& _expr);
bool createGlobalSymbol(std::string const& _name, frontend::Expression const& _expr);
/// Checks if special variable or function was seen.
bool knownGlobalSymbol(std::string const& _var) const;
//@}
@@ -158,10 +154,10 @@ private:
/// Symbolic expressions.
//{@
/// Symbolic variables.
std::unordered_map<solidity::VariableDeclaration const*, std::shared_ptr<SymbolicVariable>> m_variables;
std::unordered_map<frontend::VariableDeclaration const*, std::shared_ptr<SymbolicVariable>> m_variables;
/// Symbolic expressions.
std::unordered_map<solidity::Expression const*, std::shared_ptr<SymbolicVariable>> m_expressions;
std::unordered_map<frontend::Expression const*, std::shared_ptr<SymbolicVariable>> m_expressions;
/// Symbolic representation of global symbols including
/// variables and functions.
@@ -188,5 +184,3 @@ private:
};
}
}
}
+4 -3
View File
@@ -18,9 +18,10 @@
#include <libsolidity/formal/ModelChecker.h>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
using namespace solidity::frontend;
ModelChecker::ModelChecker(
ErrorReporter& _errorReporter,
+2 -5
View File
@@ -30,15 +30,13 @@
#include <libsolidity/interface/ReadFile.h>
#include <liblangutil/ErrorReporter.h>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
struct SourceLocation;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class ModelChecker
@@ -75,4 +73,3 @@ private:
};
}
}
+4 -3
View File
@@ -25,9 +25,10 @@
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
using namespace solidity::frontend;
SMTEncoder::SMTEncoder(smt::EncodingContext& _context):
m_errorReporter(m_smtErrors),
+2 -5
View File
@@ -36,15 +36,13 @@
#include <unordered_map>
#include <vector>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
struct SourceLocation;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class SMTEncoder: public ASTConstVisitor
@@ -274,4 +272,3 @@ protected:
};
}
}
+5 -4
View File
@@ -30,9 +30,10 @@
#include <stdexcept>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace dev::solidity::smt;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
using namespace solidity::frontend::smt;
SMTLib2Interface::SMTLib2Interface(
map<h256, string> const& _queryResponses,
@@ -231,7 +232,7 @@ vector<string> SMTLib2Interface::parseValues(string::const_iterator _start, stri
string SMTLib2Interface::querySolver(string const& _input)
{
h256 inputHash = dev::keccak256(_input);
h256 inputHash = keccak256(_input);
if (m_queryResponses.count(inputHash))
return m_queryResponses.at(inputHash);
if (m_smtCallback)
+3 -9
View File
@@ -31,18 +31,14 @@
#include <string>
#include <vector>
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
class SMTLib2Interface: public SolverInterface, public boost::noncopyable
{
public:
explicit SMTLib2Interface(
std::map<h256, std::string> const& _queryResponses,
std::map<util::h256, std::string> const& _queryResponses,
ReadCallback::Callback const& _smtCallback
);
@@ -79,12 +75,10 @@ private:
std::vector<std::string> m_accumulatedOutput;
std::map<std::string, SortPointer> m_variables;
std::map<h256, std::string> const& m_queryResponses;
std::map<util::h256, std::string> const& m_queryResponses;
std::vector<std::string> m_unhandledQueries;
ReadCallback::Callback m_smtCallback;
};
}
}
}
+4 -3
View File
@@ -26,9 +26,10 @@
#include <libsolidity/formal/SMTLib2Interface.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace dev::solidity::smt;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
using namespace solidity::frontend::smt;
SMTPortfolio::SMTPortfolio(
map<h256, string> const& _smtlib2Responses,
+2 -8
View File
@@ -26,11 +26,7 @@
#include <map>
#include <vector>
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
/**
@@ -43,7 +39,7 @@ class SMTPortfolio: public SolverInterface, public boost::noncopyable
{
public:
SMTPortfolio(
std::map<h256, std::string> const& _smtlib2Responses,
std::map<util::h256, std::string> const& _smtlib2Responses,
ReadCallback::Callback const& _smtCallback,
SMTSolverChoice _enabledSolvers
);
@@ -70,5 +66,3 @@ private:
};
}
}
}
+2 -1
View File
@@ -18,7 +18,8 @@
#include <libsolidity/formal/SSAVariable.h>
using namespace std;
using namespace dev::solidity::smt;
using namespace solidity::frontend;
using namespace solidity::frontend::smt;
SSAVariable::SSAVariable()
{
+1 -7
View File
@@ -19,11 +19,7 @@
#include <memory>
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
/**
@@ -50,5 +46,3 @@ private:
};
}
}
}
+3 -9
View File
@@ -29,11 +29,7 @@
#include <string>
#include <vector>
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
struct SMTSolverChoice
@@ -145,7 +141,7 @@ struct SortSort: public Sort
};
// Forward declaration.
SortPointer smtSort(solidity::Type const& _type);
SortPointer smtSort(Type const& _type);
/// C++ representation of an SMTLIB2 expression.
class Expression
@@ -153,7 +149,7 @@ class Expression
friend class SolverInterface;
public:
explicit Expression(bool _v): Expression(_v ? "true" : "false", Kind::Bool) {}
explicit Expression(solidity::TypePointer _type): Expression(_type->toString(), {}, std::make_shared<SortSort>(smtSort(*_type))) {}
explicit Expression(frontend::TypePointer _type): Expression(_type->toString(), {}, std::make_shared<SortSort>(smtSort(*_type))) {}
Expression(size_t _number): Expression(std::to_string(_number), Kind::Int) {}
Expression(u256 const& _number): Expression(_number.str(), Kind::Int) {}
Expression(s256 const& _number): Expression(_number.str(), Kind::Int) {}
@@ -377,5 +373,3 @@ public:
};
}
}
}
+53 -59
View File
@@ -24,14 +24,10 @@
using namespace std;
namespace dev
{
namespace solidity
{
namespace smt
namespace solidity::frontend::smt
{
SortPointer smtSort(solidity::Type const& _type)
SortPointer smtSort(frontend::Type const& _type)
{
switch (smtKind(_type.category()))
{
@@ -41,7 +37,7 @@ SortPointer smtSort(solidity::Type const& _type)
return make_shared<Sort>(Kind::Bool);
case Kind::Function:
{
auto fType = dynamic_cast<solidity::FunctionType const*>(&_type);
auto fType = dynamic_cast<frontend::FunctionType const*>(&_type);
solAssert(fType, "");
vector<SortPointer> parameterSorts = smtSort(fType->parameterTypes());
auto returnTypes = fType->returnParameterTypes();
@@ -61,13 +57,13 @@ SortPointer smtSort(solidity::Type const& _type)
{
if (isMapping(_type.category()))
{
auto mapType = dynamic_cast<solidity::MappingType const*>(&_type);
auto mapType = dynamic_cast<frontend::MappingType const*>(&_type);
solAssert(mapType, "");
return make_shared<ArraySort>(smtSortAbstractFunction(*mapType->keyType()), smtSortAbstractFunction(*mapType->valueType()));
}
else if (isStringLiteral(_type.category()))
{
auto stringLitType = dynamic_cast<solidity::StringLiteralType const*>(&_type);
auto stringLitType = dynamic_cast<frontend::StringLiteralType const*>(&_type);
solAssert(stringLitType, "");
auto intSort = make_shared<Sort>(Kind::Int);
return make_shared<ArraySort>(intSort, intSort);
@@ -75,7 +71,7 @@ SortPointer smtSort(solidity::Type const& _type)
else
{
solAssert(isArray(_type.category()), "");
auto arrayType = dynamic_cast<solidity::ArrayType const*>(&_type);
auto arrayType = dynamic_cast<frontend::ArrayType const*>(&_type);
solAssert(arrayType, "");
return make_shared<ArraySort>(make_shared<Sort>(Kind::Int), smtSortAbstractFunction(*arrayType->baseType()));
}
@@ -86,7 +82,7 @@ SortPointer smtSort(solidity::Type const& _type)
}
}
vector<SortPointer> smtSort(vector<solidity::TypePointer> const& _types)
vector<SortPointer> smtSort(vector<frontend::TypePointer> const& _types)
{
vector<SortPointer> sorts;
for (auto const& type: _types)
@@ -94,14 +90,14 @@ vector<SortPointer> smtSort(vector<solidity::TypePointer> const& _types)
return sorts;
}
SortPointer smtSortAbstractFunction(solidity::Type const& _type)
SortPointer smtSortAbstractFunction(frontend::Type const& _type)
{
if (isFunction(_type.category()))
return make_shared<Sort>(Kind::Int);
return smtSort(_type);
}
Kind smtKind(solidity::Type::Category _category)
Kind smtKind(frontend::Type::Category _category)
{
if (isNumber(_category))
return Kind::Int;
@@ -115,7 +111,7 @@ Kind smtKind(solidity::Type::Category _category)
return Kind::Int;
}
bool isSupportedType(solidity::Type::Category _category)
bool isSupportedType(frontend::Type::Category _category)
{
return isNumber(_category) ||
isBool(_category) ||
@@ -124,25 +120,25 @@ bool isSupportedType(solidity::Type::Category _category)
isTuple(_category);
}
bool isSupportedTypeDeclaration(solidity::Type::Category _category)
bool isSupportedTypeDeclaration(frontend::Type::Category _category)
{
return isSupportedType(_category) ||
isFunction(_category);
}
pair<bool, shared_ptr<SymbolicVariable>> newSymbolicVariable(
solidity::Type const& _type,
frontend::Type const& _type,
std::string const& _uniqueName,
EncodingContext& _context
)
{
bool abstract = false;
shared_ptr<SymbolicVariable> var;
solidity::TypePointer type = &_type;
frontend::TypePointer type = &_type;
if (!isSupportedTypeDeclaration(_type))
{
abstract = true;
var = make_shared<SymbolicIntVariable>(solidity::TypeProvider::uint256(), type, _uniqueName, _context);
var = make_shared<SymbolicIntVariable>(frontend::TypeProvider::uint256(), type, _uniqueName, _context);
}
else if (isBool(_type.category()))
var = make_shared<SymbolicBoolVariable>(type, _uniqueName, _context);
@@ -155,7 +151,7 @@ pair<bool, shared_ptr<SymbolicVariable>> newSymbolicVariable(
return find_if(
begin(params),
end(params),
[&](TypePointer _paramType) { return _paramType->category() == solidity::Type::Category::Function; }
[&](TypePointer _paramType) { return _paramType->category() == frontend::Type::Category::Function; }
);
};
if (
@@ -173,7 +169,7 @@ pair<bool, shared_ptr<SymbolicVariable>> newSymbolicVariable(
var = make_shared<SymbolicIntVariable>(type, type, _uniqueName, _context);
else if (isFixedBytes(_type.category()))
{
auto fixedBytesType = dynamic_cast<solidity::FixedBytesType const*>(type);
auto fixedBytesType = dynamic_cast<frontend::FixedBytesType const*>(type);
solAssert(fixedBytesType, "");
var = make_shared<SymbolicFixedBytesVariable>(type, fixedBytesType->numBytes(), _uniqueName, _context);
}
@@ -183,10 +179,10 @@ pair<bool, shared_ptr<SymbolicVariable>> newSymbolicVariable(
var = make_shared<SymbolicEnumVariable>(type, _uniqueName, _context);
else if (isRational(_type.category()))
{
auto rational = dynamic_cast<solidity::RationalNumberType const*>(&_type);
auto rational = dynamic_cast<frontend::RationalNumberType const*>(&_type);
solAssert(rational, "");
if (rational->isFractional())
var = make_shared<SymbolicIntVariable>(solidity::TypeProvider::uint256(), type, _uniqueName, _context);
var = make_shared<SymbolicIntVariable>(frontend::TypeProvider::uint256(), type, _uniqueName, _context);
else
var = make_shared<SymbolicIntVariable>(type, type, _uniqueName, _context);
}
@@ -206,47 +202,47 @@ pair<bool, shared_ptr<SymbolicVariable>> newSymbolicVariable(
return make_pair(abstract, var);
}
bool isSupportedType(solidity::Type const& _type)
bool isSupportedType(frontend::Type const& _type)
{
return isSupportedType(_type.category());
}
bool isSupportedTypeDeclaration(solidity::Type const& _type)
bool isSupportedTypeDeclaration(frontend::Type const& _type)
{
return isSupportedTypeDeclaration(_type.category());
}
bool isInteger(solidity::Type::Category _category)
bool isInteger(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Integer;
return _category == frontend::Type::Category::Integer;
}
bool isRational(solidity::Type::Category _category)
bool isRational(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::RationalNumber;
return _category == frontend::Type::Category::RationalNumber;
}
bool isFixedBytes(solidity::Type::Category _category)
bool isFixedBytes(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::FixedBytes;
return _category == frontend::Type::Category::FixedBytes;
}
bool isAddress(solidity::Type::Category _category)
bool isAddress(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Address;
return _category == frontend::Type::Category::Address;
}
bool isContract(solidity::Type::Category _category)
bool isContract(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Contract;
return _category == frontend::Type::Category::Contract;
}
bool isEnum(solidity::Type::Category _category)
bool isEnum(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Enum;
return _category == frontend::Type::Category::Enum;
}
bool isNumber(solidity::Type::Category _category)
bool isNumber(frontend::Type::Category _category)
{
return isInteger(_category) ||
isRational(_category) ||
@@ -256,43 +252,43 @@ bool isNumber(solidity::Type::Category _category)
isEnum(_category);
}
bool isBool(solidity::Type::Category _category)
bool isBool(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Bool;
return _category == frontend::Type::Category::Bool;
}
bool isFunction(solidity::Type::Category _category)
bool isFunction(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Function;
return _category == frontend::Type::Category::Function;
}
bool isMapping(solidity::Type::Category _category)
bool isMapping(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Mapping;
return _category == frontend::Type::Category::Mapping;
}
bool isArray(solidity::Type::Category _category)
bool isArray(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Array ||
_category == solidity::Type::Category::StringLiteral;
return _category == frontend::Type::Category::Array ||
_category == frontend::Type::Category::StringLiteral;
}
bool isTuple(solidity::Type::Category _category)
bool isTuple(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::Tuple;
return _category == frontend::Type::Category::Tuple;
}
bool isStringLiteral(solidity::Type::Category _category)
bool isStringLiteral(frontend::Type::Category _category)
{
return _category == solidity::Type::Category::StringLiteral;
return _category == frontend::Type::Category::StringLiteral;
}
Expression minValue(solidity::IntegerType const& _type)
Expression minValue(frontend::IntegerType const& _type)
{
return Expression(_type.minValue());
}
Expression maxValue(solidity::IntegerType const& _type)
Expression maxValue(frontend::IntegerType const& _type)
{
return Expression(_type.maxValue());
}
@@ -302,13 +298,13 @@ void setSymbolicZeroValue(SymbolicVariable const& _variable, EncodingContext& _c
setSymbolicZeroValue(_variable.currentValue(), _variable.type(), _context);
}
void setSymbolicZeroValue(Expression _expr, solidity::TypePointer const& _type, EncodingContext& _context)
void setSymbolicZeroValue(Expression _expr, frontend::TypePointer const& _type, EncodingContext& _context)
{
solAssert(_type, "");
_context.addAssertion(_expr == zeroValue(_type));
}
Expression zeroValue(solidity::TypePointer const& _type)
Expression zeroValue(frontend::TypePointer const& _type)
{
solAssert(_type, "");
if (isSupportedType(_type->category()))
@@ -336,19 +332,19 @@ void setSymbolicUnknownValue(SymbolicVariable const& _variable, EncodingContext&
setSymbolicUnknownValue(_variable.currentValue(), _variable.type(), _context);
}
void setSymbolicUnknownValue(Expression _expr, solidity::TypePointer const& _type, EncodingContext& _context)
void setSymbolicUnknownValue(Expression _expr, frontend::TypePointer const& _type, EncodingContext& _context)
{
solAssert(_type, "");
if (isEnum(_type->category()))
{
auto enumType = dynamic_cast<solidity::EnumType const*>(_type);
auto enumType = dynamic_cast<frontend::EnumType const*>(_type);
solAssert(enumType, "");
_context.addAssertion(_expr >= 0);
_context.addAssertion(_expr < enumType->numberOfMembers());
}
else if (isInteger(_type->category()))
{
auto intType = dynamic_cast<solidity::IntegerType const*>(_type);
auto intType = dynamic_cast<frontend::IntegerType const*>(_type);
solAssert(intType, "");
_context.addAssertion(_expr >= minValue(*intType));
_context.addAssertion(_expr <= maxValue(*intType));
@@ -356,5 +352,3 @@ void setSymbolicUnknownValue(Expression _expr, solidity::TypePointer const& _typ
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More