mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Eliminate using namespace std.
This commit is contained in:
parent
d8a36a1d58
commit
e4e0472407
@ -21,7 +21,6 @@
|
|||||||
#include <libsolidity/experimental/analysis/TypeInference.h>
|
#include <libsolidity/experimental/analysis/TypeInference.h>
|
||||||
#include <libsolidity/experimental/analysis/TypeRegistration.h>
|
#include <libsolidity/experimental/analysis/TypeRegistration.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::frontend::experimental;
|
using namespace solidity::frontend::experimental;
|
||||||
|
|
||||||
@ -120,7 +119,7 @@ std::tuple<std::integral_constant<size_t, Is>...> makeIndexTuple(std::index_sequ
|
|||||||
return std::make_tuple( std::integral_constant<size_t, Is>{}...);
|
return std::make_tuple( std::integral_constant<size_t, Is>{}...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Analysis::check(vector<shared_ptr<SourceUnit const>> const& _sourceUnits)
|
bool Analysis::check(std::vector<std::shared_ptr<SourceUnit const>> const& _sourceUnits)
|
||||||
{
|
{
|
||||||
using AnalysisSteps = std::tuple<SyntaxRestrictor, TypeRegistration, TypeInference, DebugWarner>;
|
using AnalysisSteps = std::tuple<SyntaxRestrictor, TypeRegistration, TypeInference, DebugWarner>;
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <range/v3/view/transform.hpp>
|
#include <range/v3/view/transform.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::experimental;
|
using namespace solidity::frontend::experimental;
|
||||||
@ -51,9 +50,9 @@ m_typeSystem(_analysis.typeSystem())
|
|||||||
_name,
|
_name,
|
||||||
nullptr
|
nullptr
|
||||||
);
|
);
|
||||||
if (auto error = get_if<string>(&result))
|
if (auto error = std::get_if<std::string>(&result))
|
||||||
solAssert(!error, *error);
|
solAssert(!error, *error);
|
||||||
TypeClass resultClass = get<TypeClass>(result);
|
TypeClass resultClass = std::get<TypeClass>(result);
|
||||||
// TODO: validation?
|
// TODO: validation?
|
||||||
annotation().typeClassFunctions[resultClass] = _memberCreator(type);
|
annotation().typeClassFunctions[resultClass] = _memberCreator(type);
|
||||||
solAssert(annotation().builtinClassesByName.emplace(_name, _class).second);
|
solAssert(annotation().builtinClassesByName.emplace(_name, _class).second);
|
||||||
@ -111,7 +110,7 @@ m_typeSystem(_analysis.typeSystem())
|
|||||||
m_env = &m_typeSystem.env();
|
m_env = &m_typeSystem.env();
|
||||||
|
|
||||||
{
|
{
|
||||||
auto [members, newlyInserted] = annotation().members.emplace(m_typeSystem.constructor(PrimitiveType::Bool), map<string, TypeMember>{});
|
auto [members, newlyInserted] = annotation().members.emplace(m_typeSystem.constructor(PrimitiveType::Bool), std::map<std::string, TypeMember>{});
|
||||||
solAssert(newlyInserted);
|
solAssert(newlyInserted);
|
||||||
members->second.emplace("abs", TypeMember{helper.functionType(m_wordType, m_boolType)});
|
members->second.emplace("abs", TypeMember{helper.functionType(m_wordType, m_boolType)});
|
||||||
members->second.emplace("rep", TypeMember{helper.functionType(m_boolType, m_wordType)});
|
members->second.emplace("rep", TypeMember{helper.functionType(m_boolType, m_wordType)});
|
||||||
@ -120,7 +119,7 @@ m_typeSystem(_analysis.typeSystem())
|
|||||||
Type first = m_typeSystem.freshTypeVariable({});
|
Type first = m_typeSystem.freshTypeVariable({});
|
||||||
Type second = m_typeSystem.freshTypeVariable({});
|
Type second = m_typeSystem.freshTypeVariable({});
|
||||||
Type pairType = m_typeSystem.type(PrimitiveType::Pair, {first, second});
|
Type pairType = m_typeSystem.type(PrimitiveType::Pair, {first, second});
|
||||||
auto [members, newlyInserted] = annotation().members.emplace(m_typeSystem.constructor(PrimitiveType::Pair), map<string, TypeMember>{});
|
auto [members, newlyInserted] = annotation().members.emplace(m_typeSystem.constructor(PrimitiveType::Pair), std::map<std::string, TypeMember>{});
|
||||||
solAssert(newlyInserted);
|
solAssert(newlyInserted);
|
||||||
members->second.emplace("first", TypeMember{helper.functionType(pairType, first)});
|
members->second.emplace("first", TypeMember{helper.functionType(pairType, first)});
|
||||||
members->second.emplace("second", TypeMember{helper.functionType(pairType, second)});
|
members->second.emplace("second", TypeMember{helper.functionType(pairType, second)});
|
||||||
@ -140,7 +139,7 @@ bool TypeInference::visit(FunctionDefinition const& _functionDefinition)
|
|||||||
if (functionAnnotation.type)
|
if (functionAnnotation.type)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ScopedSaveAndRestore signatureRestore(m_currentFunctionType, nullopt);
|
ScopedSaveAndRestore signatureRestore(m_currentFunctionType, std::nullopt);
|
||||||
|
|
||||||
Type argumentsType = m_typeSystem.freshTypeVariable({});
|
Type argumentsType = m_typeSystem.freshTypeVariable({});
|
||||||
Type returnType = m_typeSystem.freshTypeVariable({});
|
Type returnType = m_typeSystem.freshTypeVariable({});
|
||||||
@ -174,7 +173,7 @@ bool TypeInference::visit(FunctionDefinition const& _functionDefinition)
|
|||||||
void TypeInference::endVisit(Return const& _return)
|
void TypeInference::endVisit(Return const& _return)
|
||||||
{
|
{
|
||||||
solAssert(m_currentFunctionType);
|
solAssert(m_currentFunctionType);
|
||||||
Type functionReturnType = get<1>(TypeSystemHelpers{m_typeSystem}.destFunctionType(*m_currentFunctionType));
|
Type functionReturnType = std::get<1>(TypeSystemHelpers{m_typeSystem}.destFunctionType(*m_currentFunctionType));
|
||||||
if (_return.expression())
|
if (_return.expression())
|
||||||
unify(functionReturnType, getType(*_return.expression()), _return.location());
|
unify(functionReturnType, getType(*_return.expression()), _return.location());
|
||||||
else
|
else
|
||||||
@ -186,7 +185,7 @@ void TypeInference::endVisit(ParameterList const& _parameterList)
|
|||||||
auto& listAnnotation = annotation(_parameterList);
|
auto& listAnnotation = annotation(_parameterList);
|
||||||
solAssert(!listAnnotation.type);
|
solAssert(!listAnnotation.type);
|
||||||
listAnnotation.type = TypeSystemHelpers{m_typeSystem}.tupleType(
|
listAnnotation.type = TypeSystemHelpers{m_typeSystem}.tupleType(
|
||||||
_parameterList.parameters() | ranges::views::transform([&](auto _arg) { return getType(*_arg); }) | ranges::to<vector<Type>>
|
_parameterList.parameters() | ranges::views::transform([&](auto _arg) { return getType(*_arg); }) | ranges::to<std::vector<Type>>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +201,7 @@ bool TypeInference::visit(TypeClassDefinition const& _typeClassDefinition)
|
|||||||
_typeClassDefinition.typeVariable().accept(*this);
|
_typeClassDefinition.typeVariable().accept(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, Type> functionTypes;
|
std::map<std::string, Type> functionTypes;
|
||||||
|
|
||||||
Type typeVar = m_typeSystem.freshTypeVariable({});
|
Type typeVar = m_typeSystem.freshTypeVariable({});
|
||||||
auto& typeMembers = annotation().members[typeConstructor(&_typeClassDefinition)];
|
auto& typeMembers = annotation().members[typeConstructor(&_typeClassDefinition)];
|
||||||
@ -283,7 +282,7 @@ bool TypeInference::visit(InlineAssembly const& _inlineAssembly)
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
solAssert(!_inlineAssembly.annotation().analysisInfo, "");
|
solAssert(!_inlineAssembly.annotation().analysisInfo, "");
|
||||||
_inlineAssembly.annotation().analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
_inlineAssembly.annotation().analysisInfo = std::make_shared<yul::AsmAnalysisInfo>();
|
||||||
yul::AsmAnalyzer analyzer(
|
yul::AsmAnalyzer analyzer(
|
||||||
*_inlineAssembly.annotation().analysisInfo,
|
*_inlineAssembly.annotation().analysisInfo,
|
||||||
m_errorReporter,
|
m_errorReporter,
|
||||||
@ -306,7 +305,7 @@ bool TypeInference::visit(ElementaryTypeNameExpression const& _expression)
|
|||||||
case ExpressionContext::Type:
|
case ExpressionContext::Type:
|
||||||
if (auto constructor = m_analysis.annotation<TypeRegistration>(_expression).typeConstructor)
|
if (auto constructor = m_analysis.annotation<TypeRegistration>(_expression).typeConstructor)
|
||||||
{
|
{
|
||||||
vector<Type> arguments;
|
std::vector<Type> arguments;
|
||||||
std::generate_n(std::back_inserter(arguments), m_typeSystem.constructorInfo(*constructor).arguments(), [&]() {
|
std::generate_n(std::back_inserter(arguments), m_typeSystem.constructorInfo(*constructor).arguments(), [&]() {
|
||||||
return m_typeSystem.freshTypeVariable({});
|
return m_typeSystem.freshTypeVariable({});
|
||||||
});
|
});
|
||||||
@ -631,7 +630,7 @@ void TypeInference::endVisit(TupleExpression const& _tupleExpression)
|
|||||||
auto& componentAnnotation = annotation(*_expr);
|
auto& componentAnnotation = annotation(*_expr);
|
||||||
solAssert(componentAnnotation.type);
|
solAssert(componentAnnotation.type);
|
||||||
return *componentAnnotation.type;
|
return *componentAnnotation.type;
|
||||||
}) | ranges::to<vector<Type>>;
|
}) | ranges::to<std::vector<Type>>;
|
||||||
switch (m_expressionContext)
|
switch (m_expressionContext)
|
||||||
{
|
{
|
||||||
case ExpressionContext::Term:
|
case ExpressionContext::Term:
|
||||||
@ -666,7 +665,7 @@ bool TypeInference::visit(IdentifierPath const& _identifierPath)
|
|||||||
|
|
||||||
bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
|
bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
|
||||||
{
|
{
|
||||||
ScopedSaveAndRestore activeInstantiations{m_activeInstantiations, m_activeInstantiations + set<TypeClassInstantiation const*>{&_typeClassInstantiation}};
|
ScopedSaveAndRestore activeInstantiations{m_activeInstantiations, m_activeInstantiations + std::set<TypeClassInstantiation const*>{&_typeClassInstantiation}};
|
||||||
// Note: recursion is resolved due to special handling during unification.
|
// Note: recursion is resolved due to special handling during unification.
|
||||||
auto& instantiationAnnotation = annotation(_typeClassInstantiation);
|
auto& instantiationAnnotation = annotation(_typeClassInstantiation);
|
||||||
if (instantiationAnnotation.type)
|
if (instantiationAnnotation.type)
|
||||||
@ -686,7 +685,7 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_errorReporter.typeError(0000_error, _typeClassInstantiation.typeClass().location(), "Expected type class.");
|
m_errorReporter.typeError(0000_error, _typeClassInstantiation.typeClass().location(), "Expected type class.");
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[&](Token _token) -> std::optional<TypeClass> {
|
[&](Token _token) -> std::optional<TypeClass> {
|
||||||
@ -694,7 +693,7 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
|
|||||||
if (auto typeClass = util::valueOrNullptr(annotation().builtinClasses, *builtinClass))
|
if (auto typeClass = util::valueOrNullptr(annotation().builtinClasses, *builtinClass))
|
||||||
return *typeClass;
|
return *typeClass;
|
||||||
m_errorReporter.typeError(0000_error, _typeClassInstantiation.location(), "Invalid type class name.");
|
m_errorReporter.typeError(0000_error, _typeClassInstantiation.location(), "Invalid type class name.");
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}, _typeClassInstantiation.typeClass().name());
|
}, _typeClassInstantiation.typeClass().name());
|
||||||
if (!typeClass)
|
if (!typeClass)
|
||||||
@ -708,7 +707,7 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Type> arguments;
|
std::vector<Type> arguments;
|
||||||
Arity arity{
|
Arity arity{
|
||||||
{},
|
{},
|
||||||
*typeClass
|
*typeClass
|
||||||
@ -724,13 +723,13 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
|
|||||||
arguments = TypeSystemHelpers{m_typeSystem}.destTupleType(*argumentSortAnnotation.type);
|
arguments = TypeSystemHelpers{m_typeSystem}.destTupleType(*argumentSortAnnotation.type);
|
||||||
arity.argumentSorts = arguments | ranges::views::transform([&](Type _type) {
|
arity.argumentSorts = arguments | ranges::views::transform([&](Type _type) {
|
||||||
return m_env->sort(_type);
|
return m_env->sort(_type);
|
||||||
}) | ranges::to<vector<Sort>>;
|
}) | ranges::to<std::vector<Sort>>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Type type{TypeConstant{*typeConstructor, arguments}};
|
Type type{TypeConstant{*typeConstructor, arguments}};
|
||||||
|
|
||||||
map<string, Type> functionTypes;
|
std::map<std::string, Type> functionTypes;
|
||||||
|
|
||||||
for (auto subNode: _typeClassInstantiation.subNodes())
|
for (auto subNode: _typeClassInstantiation.subNodes())
|
||||||
{
|
{
|
||||||
@ -834,7 +833,7 @@ bool TypeInference::visit(TypeDefinition const& _typeDefinition)
|
|||||||
underlyingType = annotation(*_typeDefinition.typeExpression()).type;
|
underlyingType = annotation(*_typeDefinition.typeExpression()).type;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Type> arguments;
|
std::vector<Type> arguments;
|
||||||
if (_typeDefinition.arguments())
|
if (_typeDefinition.arguments())
|
||||||
for (size_t i = 0; i < _typeDefinition.arguments()->parameters().size(); ++i)
|
for (size_t i = 0; i < _typeDefinition.arguments()->parameters().size(); ++i)
|
||||||
arguments.emplace_back(m_typeSystem.freshTypeVariable({}));
|
arguments.emplace_back(m_typeSystem.freshTypeVariable({}));
|
||||||
@ -846,7 +845,7 @@ bool TypeInference::visit(TypeDefinition const& _typeDefinition)
|
|||||||
typeDefinitionAnnotation.type = helper.typeFunctionType(helper.tupleType(arguments), definedType);
|
typeDefinitionAnnotation.type = helper.typeFunctionType(helper.tupleType(arguments), definedType);
|
||||||
|
|
||||||
TypeConstructor constructor = typeConstructor(&_typeDefinition);
|
TypeConstructor constructor = typeConstructor(&_typeDefinition);
|
||||||
auto [members, newlyInserted] = annotation().members.emplace(constructor, map<string, TypeMember>{});
|
auto [members, newlyInserted] = annotation().members.emplace(constructor, std::map<std::string, TypeMember>{});
|
||||||
solAssert(newlyInserted);
|
solAssert(newlyInserted);
|
||||||
if (underlyingType)
|
if (underlyingType)
|
||||||
{
|
{
|
||||||
@ -910,7 +909,7 @@ void TypeInference::endVisit(FunctionCall const& _functionCall)
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
optional<rational> parseRational(string const& _value)
|
std::optional<rational> parseRational(std::string const& _value)
|
||||||
{
|
{
|
||||||
rational value;
|
rational value;
|
||||||
try
|
try
|
||||||
@ -923,7 +922,7 @@ optional<rational> parseRational(string const& _value)
|
|||||||
!all_of(radixPoint + 1, _value.end(), util::isDigit) ||
|
!all_of(radixPoint + 1, _value.end(), util::isDigit) ||
|
||||||
!all_of(_value.begin(), radixPoint, util::isDigit)
|
!all_of(_value.begin(), radixPoint, util::isDigit)
|
||||||
)
|
)
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
// Only decimal notation allowed here, leading zeros would switch to octal.
|
// Only decimal notation allowed here, leading zeros would switch to octal.
|
||||||
auto fractionalBegin = find_if_not(
|
auto fractionalBegin = find_if_not(
|
||||||
@ -935,12 +934,12 @@ optional<rational> parseRational(string const& _value)
|
|||||||
rational numerator;
|
rational numerator;
|
||||||
rational denominator(1);
|
rational denominator(1);
|
||||||
|
|
||||||
denominator = bigint(string(fractionalBegin, _value.end()));
|
denominator = bigint(std::string(fractionalBegin, _value.end()));
|
||||||
denominator /= boost::multiprecision::pow(
|
denominator /= boost::multiprecision::pow(
|
||||||
bigint(10),
|
bigint(10),
|
||||||
static_cast<unsigned>(distance(radixPoint + 1, _value.end()))
|
static_cast<unsigned>(distance(radixPoint + 1, _value.end()))
|
||||||
);
|
);
|
||||||
numerator = bigint(string(_value.begin(), radixPoint));
|
numerator = bigint(std::string(_value.begin(), radixPoint));
|
||||||
value = numerator + denominator;
|
value = numerator + denominator;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -949,7 +948,7 @@ optional<rational> parseRational(string const& _value)
|
|||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -960,7 +959,7 @@ bool fitsPrecisionBase10(bigint const& _mantissa, uint32_t _expBase10)
|
|||||||
return fitsPrecisionBaseX(_mantissa, log2Of10AwayFromZero, _expBase10);
|
return fitsPrecisionBaseX(_mantissa, log2Of10AwayFromZero, _expBase10);
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<rational> rationalValue(Literal const& _literal)
|
std::optional<rational> rationalValue(Literal const& _literal)
|
||||||
{
|
{
|
||||||
rational value;
|
rational value;
|
||||||
try
|
try
|
||||||
@ -979,27 +978,27 @@ optional<rational> rationalValue(Literal const& _literal)
|
|||||||
else if (expPoint != valueString.end())
|
else if (expPoint != valueString.end())
|
||||||
{
|
{
|
||||||
// Parse mantissa and exponent. Checks numeric limit.
|
// Parse mantissa and exponent. Checks numeric limit.
|
||||||
optional<rational> mantissa = parseRational(string(valueString.begin(), expPoint));
|
std::optional<rational> mantissa = parseRational(std::string(valueString.begin(), expPoint));
|
||||||
|
|
||||||
if (!mantissa)
|
if (!mantissa)
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
value = *mantissa;
|
value = *mantissa;
|
||||||
|
|
||||||
// 0E... is always zero.
|
// 0E... is always zero.
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
bigint exp = bigint(string(expPoint + 1, valueString.end()));
|
bigint exp = bigint(std::string(expPoint + 1, valueString.end()));
|
||||||
|
|
||||||
if (exp > numeric_limits<int32_t>::max() || exp < numeric_limits<int32_t>::min())
|
if (exp > std::numeric_limits<int32_t>::max() || exp < std::numeric_limits<int32_t>::min())
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
uint32_t expAbs = bigint(abs(exp)).convert_to<uint32_t>();
|
uint32_t expAbs = bigint(abs(exp)).convert_to<uint32_t>();
|
||||||
|
|
||||||
if (exp < 0)
|
if (exp < 0)
|
||||||
{
|
{
|
||||||
if (!fitsPrecisionBase10(abs(value.denominator()), expAbs))
|
if (!fitsPrecisionBase10(abs(value.denominator()), expAbs))
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
value /= boost::multiprecision::pow(
|
value /= boost::multiprecision::pow(
|
||||||
bigint(10),
|
bigint(10),
|
||||||
expAbs
|
expAbs
|
||||||
@ -1008,7 +1007,7 @@ optional<rational> rationalValue(Literal const& _literal)
|
|||||||
else if (exp > 0)
|
else if (exp > 0)
|
||||||
{
|
{
|
||||||
if (!fitsPrecisionBase10(abs(value.numerator()), expAbs))
|
if (!fitsPrecisionBase10(abs(value.numerator()), expAbs))
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
value *= boost::multiprecision::pow(
|
value *= boost::multiprecision::pow(
|
||||||
bigint(10),
|
bigint(10),
|
||||||
expAbs
|
expAbs
|
||||||
@ -1018,15 +1017,15 @@ optional<rational> rationalValue(Literal const& _literal)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// parse as rational number
|
// parse as rational number
|
||||||
optional<rational> tmp = parseRational(valueString);
|
std::optional<rational> tmp = parseRational(valueString);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
value = *tmp;
|
value = *tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
switch (_literal.subDenomination())
|
switch (_literal.subDenomination())
|
||||||
{
|
{
|
||||||
@ -1069,7 +1068,7 @@ bool TypeInference::visit(Literal const& _literal)
|
|||||||
m_errorReporter.typeError(0000_error, _literal.location(), "Only number literals are supported.");
|
m_errorReporter.typeError(0000_error, _literal.location(), "Only number literals are supported.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
optional<rational> value = rationalValue(_literal);
|
std::optional<rational> value = rationalValue(_literal);
|
||||||
if (!value)
|
if (!value)
|
||||||
{
|
{
|
||||||
m_errorReporter.typeError(0000_error, _literal.location(), "Invalid number literals.");
|
m_errorReporter.typeError(0000_error, _literal.location(), "Invalid number literals.");
|
||||||
@ -1127,7 +1126,7 @@ void TypeInference::unify(Type _a, Type _b, langutil::SourceLocation _location)
|
|||||||
bool onlyMissingInstantiations = [&]() {
|
bool onlyMissingInstantiations = [&]() {
|
||||||
for (auto failure: unificationFailures)
|
for (auto failure: unificationFailures)
|
||||||
{
|
{
|
||||||
if (auto* sortMismatch = get_if<TypeEnvironment::SortMismatch>(&failure))
|
if (auto* sortMismatch = std::get_if<TypeEnvironment::SortMismatch>(&failure))
|
||||||
if (helper.isTypeConstant(sortMismatch->type))
|
if (helper.isTypeConstant(sortMismatch->type))
|
||||||
{
|
{
|
||||||
TypeConstructor constructor = std::get<0>(helper.destTypeConstant(sortMismatch->type));
|
TypeConstructor constructor = std::get<0>(helper.destTypeConstant(sortMismatch->type));
|
||||||
@ -1220,7 +1219,7 @@ TypeConstructor TypeInference::typeConstructor(Declaration const* _type) const
|
|||||||
m_errorReporter.fatalTypeError(0000_error, _type->location(), "Unregistered type.");
|
m_errorReporter.fatalTypeError(0000_error, _type->location(), "Unregistered type.");
|
||||||
util::unreachable();
|
util::unreachable();
|
||||||
}
|
}
|
||||||
experimental::Type TypeInference::type(Declaration const* _type, vector<Type> _arguments) const
|
experimental::Type TypeInference::type(Declaration const* _type, std::vector<Type> _arguments) const
|
||||||
{
|
{
|
||||||
return m_typeSystem.type(typeConstructor(_type), std::move(_arguments));
|
return m_typeSystem.type(typeConstructor(_type), std::move(_arguments));
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#include <libyul/AsmAnalysisInfo.h>
|
#include <libyul/AsmAnalysisInfo.h>
|
||||||
#include <libyul/AST.h>
|
#include <libyul/AST.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::experimental;
|
using namespace solidity::frontend::experimental;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
@ -61,7 +60,7 @@ bool TypeRegistration::visit(ElementaryTypeName const& _typeName)
|
|||||||
{
|
{
|
||||||
if (annotation(_typeName).typeConstructor)
|
if (annotation(_typeName).typeConstructor)
|
||||||
return false;
|
return false;
|
||||||
annotation(_typeName).typeConstructor = [&]() -> optional<TypeConstructor> {
|
annotation(_typeName).typeConstructor = [&]() -> std::optional<TypeConstructor> {
|
||||||
switch(_typeName.typeName().token())
|
switch(_typeName.typeName().token())
|
||||||
{
|
{
|
||||||
case Token::Void:
|
case Token::Void:
|
||||||
@ -80,7 +79,7 @@ bool TypeRegistration::visit(ElementaryTypeName const& _typeName)
|
|||||||
return m_typeSystem.constructor(PrimitiveType::Bool);
|
return m_typeSystem.constructor(PrimitiveType::Bool);
|
||||||
default:
|
default:
|
||||||
m_errorReporter.fatalTypeError(0000_error, _typeName.location(), "Expected primitive type.");
|
m_errorReporter.fatalTypeError(0000_error, _typeName.location(), "Expected primitive type.");
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
return true;
|
return true;
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::frontend::experimental;
|
using namespace solidity::frontend::experimental;
|
||||||
|
|
||||||
|
@ -32,14 +32,13 @@
|
|||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::experimental;
|
using namespace solidity::frontend::experimental;
|
||||||
|
|
||||||
vector<TypeEnvironment::UnificationFailure> TypeEnvironment::unify(Type _a, Type _b)
|
std::vector<TypeEnvironment::UnificationFailure> TypeEnvironment::unify(Type _a, Type _b)
|
||||||
{
|
{
|
||||||
vector<UnificationFailure> failures;
|
std::vector<UnificationFailure> failures;
|
||||||
auto unificationFailure = [&]() {
|
auto unificationFailure = [&]() {
|
||||||
failures.emplace_back(UnificationFailure{TypeMismatch{_a, _b}});
|
failures.emplace_back(UnificationFailure{TypeMismatch{_a, _b}});
|
||||||
};
|
};
|
||||||
@ -151,9 +150,9 @@ TypeSystem::TypeSystem()
|
|||||||
TypeClass classType = primitiveClass(PrimitiveClass::Type);
|
TypeClass classType = primitiveClass(PrimitiveClass::Type);
|
||||||
//TypeClass classKind = primitiveClass(PrimitiveClass::Kind);
|
//TypeClass classKind = primitiveClass(PrimitiveClass::Kind);
|
||||||
Sort typeSort{{classType}};
|
Sort typeSort{{classType}};
|
||||||
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::TypeFunction).m_index).arities = {Arity{vector<Sort>{{typeSort},{typeSort}}, classType}};
|
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::TypeFunction).m_index).arities = {Arity{std::vector<Sort>{{typeSort},{typeSort}}, classType}};
|
||||||
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{vector<Sort>{{typeSort, typeSort}}, classType}};
|
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{std::vector<Sort>{{typeSort, typeSort}}, classType}};
|
||||||
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{vector<Sort>{{typeSort, typeSort}}, classType}};
|
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{std::vector<Sort>{{typeSort, typeSort}}, classType}};
|
||||||
}
|
}
|
||||||
|
|
||||||
experimental::Type TypeSystem::freshVariable(Sort _sort)
|
experimental::Type TypeSystem::freshVariable(Sort _sort)
|
||||||
@ -168,7 +167,7 @@ experimental::Type TypeSystem::freshTypeVariable(Sort _sort)
|
|||||||
return freshVariable(_sort);
|
return freshVariable(_sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<TypeEnvironment::UnificationFailure> TypeEnvironment::instantiate(TypeVariable _variable, Type _type)
|
std::vector<TypeEnvironment::UnificationFailure> TypeEnvironment::instantiate(TypeVariable _variable, Type _type)
|
||||||
{
|
{
|
||||||
for (auto typeVar: TypeEnvironmentHelpers{*this}.typeVars(_type))
|
for (auto typeVar: TypeEnvironmentHelpers{*this}.typeVars(_type))
|
||||||
if (typeVar.index() == _variable.index())
|
if (typeVar.index() == _variable.index())
|
||||||
@ -201,7 +200,7 @@ experimental::Type TypeEnvironment::resolveRecursive(Type _type) const
|
|||||||
_type.constructor,
|
_type.constructor,
|
||||||
_type.arguments | ranges::views::transform([&](Type _argType) {
|
_type.arguments | ranges::views::transform([&](Type _argType) {
|
||||||
return resolveRecursive(_argType);
|
return resolveRecursive(_argType);
|
||||||
}) | ranges::to<vector<Type>>
|
}) | ranges::to<std::vector<Type>>
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[&](TypeVariable const&) -> Type {
|
[&](TypeVariable const&) -> Type {
|
||||||
@ -221,7 +220,7 @@ Sort TypeEnvironment::sort(Type _type) const
|
|||||||
auto const& constructorInfo = m_typeSystem.constructorInfo(_expression.constructor);
|
auto const& constructorInfo = m_typeSystem.constructorInfo(_expression.constructor);
|
||||||
auto argumentSorts = _expression.arguments | ranges::views::transform([&](Type _argumentType) {
|
auto argumentSorts = _expression.arguments | ranges::views::transform([&](Type _argumentType) {
|
||||||
return sort(resolve(_argumentType));
|
return sort(resolve(_argumentType));
|
||||||
}) | ranges::to<vector<Sort>>;
|
}) | ranges::to<std::vector<Sort>>;
|
||||||
Sort sort;
|
Sort sort;
|
||||||
for (auto const& arity: constructorInfo.arities)
|
for (auto const& arity: constructorInfo.arities)
|
||||||
{
|
{
|
||||||
@ -246,7 +245,7 @@ Sort TypeEnvironment::sort(Type _type) const
|
|||||||
}, _type);
|
}, _type);
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeConstructor TypeSystem::declareTypeConstructor(string _name, string _canonicalName, size_t _arguments, Declaration const* _declaration)
|
TypeConstructor TypeSystem::declareTypeConstructor(std::string _name, std::string _canonicalName, size_t _arguments, Declaration const* _declaration)
|
||||||
{
|
{
|
||||||
solAssert(m_canonicalTypeNames.insert(_canonicalName).second, "Duplicate canonical type name.");
|
solAssert(m_canonicalTypeNames.insert(_canonicalName).second, "Duplicate canonical type name.");
|
||||||
Sort baseSort{{primitiveClass(PrimitiveClass::Type)}};
|
Sort baseSort{{primitiveClass(PrimitiveClass::Type)}};
|
||||||
@ -254,7 +253,7 @@ TypeConstructor TypeSystem::declareTypeConstructor(string _name, string _canonic
|
|||||||
m_typeConstructors.emplace_back(TypeConstructorInfo{
|
m_typeConstructors.emplace_back(TypeConstructorInfo{
|
||||||
_name,
|
_name,
|
||||||
_canonicalName,
|
_canonicalName,
|
||||||
{Arity{vector<Sort>{_arguments, baseSort}, primitiveClass(PrimitiveClass::Type)}},
|
{Arity{std::vector<Sort>{_arguments, baseSort}, primitiveClass(PrimitiveClass::Type)}},
|
||||||
_declaration
|
_declaration
|
||||||
});
|
});
|
||||||
TypeConstructor constructor{index};
|
TypeConstructor constructor{index};
|
||||||
@ -277,7 +276,7 @@ TypeConstructor TypeSystem::declareTypeConstructor(string _name, string _canonic
|
|||||||
|
|
||||||
std::variant<TypeClass, std::string> TypeSystem::declareTypeClass(Type _typeVariable, std::string _name, Declaration const* _declaration)
|
std::variant<TypeClass, std::string> TypeSystem::declareTypeClass(Type _typeVariable, std::string _name, Declaration const* _declaration)
|
||||||
{
|
{
|
||||||
TypeVariable const* typeVariable = get_if<TypeVariable>(&_typeVariable);
|
TypeVariable const* typeVariable = std::get_if<TypeVariable>(&_typeVariable);
|
||||||
if (!typeVariable)
|
if (!typeVariable)
|
||||||
return "Invalid type variable.";
|
return "Invalid type variable.";
|
||||||
|
|
||||||
@ -310,13 +309,13 @@ experimental::Type TypeEnvironment::fresh(Type _type)
|
|||||||
_type.constructor,
|
_type.constructor,
|
||||||
_type.arguments | ranges::views::transform([&](Type _argType) {
|
_type.arguments | ranges::views::transform([&](Type _argType) {
|
||||||
return _recurse(_argType, _recurse);
|
return _recurse(_argType, _recurse);
|
||||||
}) | ranges::to<vector<Type>>
|
}) | ranges::to<std::vector<Type>>
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[&](TypeVariable const& _var) -> Type {
|
[&](TypeVariable const& _var) -> Type {
|
||||||
if (auto* mapped = util::valueOrNullptr(mapping, _var.index()))
|
if (auto* mapped = util::valueOrNullptr(mapping, _var.index()))
|
||||||
{
|
{
|
||||||
auto* typeVariable = get_if<TypeVariable>(mapped);
|
auto* typeVariable = std::get_if<TypeVariable>(mapped);
|
||||||
solAssert(typeVariable);
|
solAssert(typeVariable);
|
||||||
// TODO: can there be a mismatch?
|
// TODO: can there be a mismatch?
|
||||||
solAssert(typeVariable->sort() == _var.sort());
|
solAssert(typeVariable->sort() == _var.sort());
|
||||||
@ -343,5 +342,5 @@ std::optional<std::string> TypeSystem::instantiateClass(Type _instanceVariable,
|
|||||||
|
|
||||||
typeConstructorInfo.arities.emplace_back(_arity);
|
typeConstructorInfo.arities.emplace_back(_arity);
|
||||||
|
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::experimental;
|
using namespace solidity::frontend::experimental;
|
||||||
@ -97,7 +96,7 @@ std::optional<BuiltinClass> experimental::builtinClassFromToken(langutil::Token
|
|||||||
case Token::GreaterThanOrEqual:
|
case Token::GreaterThanOrEqual:
|
||||||
return BuiltinClass::GreaterOrEqual;
|
return BuiltinClass::GreaterOrEqual;
|
||||||
default:
|
default:
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -116,7 +115,7 @@ std::optional<TypeClass> experimental::typeClassFromTypeClassName(TypeClassName
|
|||||||
}, _typeClass.name());
|
}, _typeClass.name());
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
experimental::Type TypeSystemHelpers::tupleType(vector<Type> _elements) const
|
experimental::Type TypeSystemHelpers::tupleType(std::vector<Type> _elements) const
|
||||||
{
|
{
|
||||||
if (_elements.empty())
|
if (_elements.empty())
|
||||||
return typeSystem.type(PrimitiveType::Unit, {});
|
return typeSystem.type(PrimitiveType::Unit, {});
|
||||||
@ -128,7 +127,7 @@ experimental::Type TypeSystemHelpers::tupleType(vector<Type> _elements) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<experimental::Type> TypeSystemHelpers::destTupleType(Type _tupleType) const
|
std::vector<experimental::Type> TypeSystemHelpers::destTupleType(Type _tupleType) const
|
||||||
{
|
{
|
||||||
if (!isTypeConstant(_tupleType))
|
if (!isTypeConstant(_tupleType))
|
||||||
return {_tupleType};
|
return {_tupleType};
|
||||||
@ -140,7 +139,7 @@ vector<experimental::Type> TypeSystemHelpers::destTupleType(Type _tupleType) con
|
|||||||
return {_tupleType};
|
return {_tupleType};
|
||||||
solAssert(arguments.size() == 2);
|
solAssert(arguments.size() == 2);
|
||||||
|
|
||||||
vector<Type> result;
|
std::vector<Type> result;
|
||||||
result.emplace_back(arguments.front());
|
result.emplace_back(arguments.front());
|
||||||
Type tail = arguments.back();
|
Type tail = arguments.back();
|
||||||
while(true)
|
while(true)
|
||||||
@ -158,7 +157,7 @@ vector<experimental::Type> TypeSystemHelpers::destTupleType(Type _tupleType) con
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
experimental::Type TypeSystemHelpers::sumType(vector<Type> _elements) const
|
experimental::Type TypeSystemHelpers::sumType(std::vector<Type> _elements) const
|
||||||
{
|
{
|
||||||
if (_elements.empty())
|
if (_elements.empty())
|
||||||
return typeSystem.type(PrimitiveType::Void, {});
|
return typeSystem.type(PrimitiveType::Void, {});
|
||||||
@ -170,7 +169,7 @@ experimental::Type TypeSystemHelpers::sumType(vector<Type> _elements) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<experimental::Type> TypeSystemHelpers::destSumType(Type _tupleType) const
|
std::vector<experimental::Type> TypeSystemHelpers::destSumType(Type _tupleType) const
|
||||||
{
|
{
|
||||||
if (!isTypeConstant(_tupleType))
|
if (!isTypeConstant(_tupleType))
|
||||||
return {_tupleType};
|
return {_tupleType};
|
||||||
@ -182,7 +181,7 @@ vector<experimental::Type> TypeSystemHelpers::destSumType(Type _tupleType) const
|
|||||||
return {_tupleType};
|
return {_tupleType};
|
||||||
solAssert(arguments.size() == 2);
|
solAssert(arguments.size() == 2);
|
||||||
|
|
||||||
vector<Type> result;
|
std::vector<Type> result;
|
||||||
result.emplace_back(arguments.front());
|
result.emplace_back(arguments.front());
|
||||||
Type tail = arguments.back();
|
Type tail = arguments.back();
|
||||||
while(true)
|
while(true)
|
||||||
@ -200,9 +199,9 @@ vector<experimental::Type> TypeSystemHelpers::destSumType(Type _tupleType) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple<TypeConstructor, vector<experimental::Type>> TypeSystemHelpers::destTypeConstant(Type _type) const
|
std::tuple<TypeConstructor, std::vector<experimental::Type>> TypeSystemHelpers::destTypeConstant(Type _type) const
|
||||||
{
|
{
|
||||||
using ResultType = tuple<TypeConstructor, vector<Type>>;
|
using ResultType = std::tuple<TypeConstructor, std::vector<Type>>;
|
||||||
return std::visit(util::GenericVisitor{
|
return std::visit(util::GenericVisitor{
|
||||||
[&](TypeConstant const& _type) -> ResultType {
|
[&](TypeConstant const& _type) -> ResultType {
|
||||||
return std::make_tuple(_type.constructor, _type.arguments);
|
return std::make_tuple(_type.constructor, _type.arguments);
|
||||||
@ -230,19 +229,19 @@ experimental::Type TypeSystemHelpers::functionType(experimental::Type _argType,
|
|||||||
return typeSystem.type(PrimitiveType::Function, {_argType, _resultType});
|
return typeSystem.type(PrimitiveType::Function, {_argType, _resultType});
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple<experimental::Type, experimental::Type> TypeSystemHelpers::destFunctionType(Type _functionType) const
|
std::tuple<experimental::Type, experimental::Type> TypeSystemHelpers::destFunctionType(Type _functionType) const
|
||||||
{
|
{
|
||||||
auto [constructor, arguments] = destTypeConstant(_functionType);
|
auto [constructor, arguments] = destTypeConstant(_functionType);
|
||||||
solAssert(constructor == typeSystem.constructor(PrimitiveType::Function));
|
solAssert(constructor == typeSystem.constructor(PrimitiveType::Function));
|
||||||
solAssert(arguments.size() == 2);
|
solAssert(arguments.size() == 2);
|
||||||
return make_tuple(arguments.front(), arguments.back());
|
return std::make_tuple(arguments.front(), arguments.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TypeSystemHelpers::isFunctionType(Type _type) const
|
bool TypeSystemHelpers::isFunctionType(Type _type) const
|
||||||
{
|
{
|
||||||
if (!isTypeConstant(_type))
|
if (!isTypeConstant(_type))
|
||||||
return false;
|
return false;
|
||||||
auto constructor = get<0>(destTypeConstant(_type));
|
auto constructor = std::get<0>(destTypeConstant(_type));
|
||||||
return constructor == typeSystem.constructor(PrimitiveType::Function);
|
return constructor == typeSystem.constructor(PrimitiveType::Function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,26 +250,26 @@ experimental::Type TypeSystemHelpers::typeFunctionType(experimental::Type _argTy
|
|||||||
return typeSystem.type(PrimitiveType::TypeFunction, {_argType, _resultType});
|
return typeSystem.type(PrimitiveType::TypeFunction, {_argType, _resultType});
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple<experimental::Type, experimental::Type> TypeSystemHelpers::destTypeFunctionType(Type _functionType) const
|
std::tuple<experimental::Type, experimental::Type> TypeSystemHelpers::destTypeFunctionType(Type _functionType) const
|
||||||
{
|
{
|
||||||
auto [constructor, arguments] = destTypeConstant(_functionType);
|
auto [constructor, arguments] = destTypeConstant(_functionType);
|
||||||
solAssert(constructor == typeSystem.constructor(PrimitiveType::TypeFunction));
|
solAssert(constructor == typeSystem.constructor(PrimitiveType::TypeFunction));
|
||||||
solAssert(arguments.size() == 2);
|
solAssert(arguments.size() == 2);
|
||||||
return make_tuple(arguments.front(), arguments.back());
|
return std::make_tuple(arguments.front(), arguments.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TypeSystemHelpers::isTypeFunctionType(Type _type) const
|
bool TypeSystemHelpers::isTypeFunctionType(Type _type) const
|
||||||
{
|
{
|
||||||
if (!isTypeConstant(_type))
|
if (!isTypeConstant(_type))
|
||||||
return false;
|
return false;
|
||||||
auto constructor = get<0>(destTypeConstant(_type));
|
auto constructor = std::get<0>(destTypeConstant(_type));
|
||||||
return constructor == typeSystem.constructor(PrimitiveType::TypeFunction);
|
return constructor == typeSystem.constructor(PrimitiveType::TypeFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<experimental::Type> TypeEnvironmentHelpers::typeVars(Type _type) const
|
std::vector<experimental::Type> TypeEnvironmentHelpers::typeVars(Type _type) const
|
||||||
{
|
{
|
||||||
set<size_t> indices;
|
std::set<size_t> indices;
|
||||||
vector<Type> typeVars;
|
std::vector<Type> typeVars;
|
||||||
auto typeVarsImpl = [&](Type _type, auto _recurse) -> void {
|
auto typeVarsImpl = [&](Type _type, auto _recurse) -> void {
|
||||||
std::visit(util::GenericVisitor{
|
std::visit(util::GenericVisitor{
|
||||||
[&](TypeConstant const& _type) {
|
[&](TypeConstant const& _type) {
|
||||||
@ -310,10 +309,10 @@ std::string TypeSystemHelpers::sortToString(Sort _sort) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string TypeEnvironmentHelpers::canonicalTypeName(Type _type) const
|
std::string TypeEnvironmentHelpers::canonicalTypeName(Type _type) const
|
||||||
{
|
{
|
||||||
return visit(util::GenericVisitor{
|
return visit(util::GenericVisitor{
|
||||||
[&](TypeConstant _type) -> string {
|
[&](TypeConstant _type) -> std::string {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << env.typeSystem().constructorInfo(_type.constructor).canonicalName;
|
stream << env.typeSystem().constructorInfo(_type.constructor).canonicalName;
|
||||||
if (!_type.arguments.empty())
|
if (!_type.arguments.empty())
|
||||||
@ -326,10 +325,10 @@ string TypeEnvironmentHelpers::canonicalTypeName(Type _type) const
|
|||||||
}
|
}
|
||||||
return stream.str();
|
return stream.str();
|
||||||
},
|
},
|
||||||
[](TypeVariable) -> string {
|
[](TypeVariable) -> std::string {
|
||||||
solAssert(false);
|
solAssert(false);
|
||||||
},
|
},
|
||||||
[](std::monostate) -> string {
|
[](std::monostate) -> std::string {
|
||||||
solAssert(false);
|
solAssert(false);
|
||||||
},
|
},
|
||||||
}, env.resolve(_type));
|
}, env.resolve(_type));
|
||||||
@ -337,7 +336,7 @@ string TypeEnvironmentHelpers::canonicalTypeName(Type _type) const
|
|||||||
|
|
||||||
std::string TypeEnvironmentHelpers::typeToString(Type const& _type) const
|
std::string TypeEnvironmentHelpers::typeToString(Type const& _type) const
|
||||||
{
|
{
|
||||||
std::map<TypeConstructor, std::function<string(std::vector<Type>)>> formatters{
|
std::map<TypeConstructor, std::function<std::string(std::vector<Type>)>> formatters{
|
||||||
{env.typeSystem().constructor(PrimitiveType::Function), [&](auto const& _args) {
|
{env.typeSystem().constructor(PrimitiveType::Function), [&](auto const& _args) {
|
||||||
solAssert(_args.size() == 2);
|
solAssert(_args.size() == 2);
|
||||||
return fmt::format("{} -> {}", typeToString(_args.front()), typeToString(_args.back()));
|
return fmt::format("{} -> {}", typeToString(_args.front()), typeToString(_args.back()));
|
||||||
@ -348,7 +347,7 @@ std::string TypeEnvironmentHelpers::typeToString(Type const& _type) const
|
|||||||
}},
|
}},
|
||||||
{env.typeSystem().constructor(PrimitiveType::Pair), [&](auto const& _arguments) {
|
{env.typeSystem().constructor(PrimitiveType::Pair), [&](auto const& _arguments) {
|
||||||
auto tupleTypes = TypeSystemHelpers{env.typeSystem()}.destTupleType(_arguments.back());
|
auto tupleTypes = TypeSystemHelpers{env.typeSystem()}.destTupleType(_arguments.back());
|
||||||
string result = "(";
|
std::string result = "(";
|
||||||
result += typeToString(_arguments.front());
|
result += typeToString(_arguments.front());
|
||||||
for (auto type: tupleTypes)
|
for (auto type: tupleTypes)
|
||||||
result += ", " + typeToString(type);
|
result += ", " + typeToString(type);
|
||||||
@ -398,6 +397,6 @@ std::string TypeEnvironmentHelpers::typeToString(Type const& _type) const
|
|||||||
}
|
}
|
||||||
return stream.str();
|
return stream.str();
|
||||||
},
|
},
|
||||||
[](std::monostate) -> string { solAssert(false); }
|
[](std::monostate) -> std::string { solAssert(false); }
|
||||||
}, env.resolve(_type));
|
}, env.resolve(_type));
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include <libyul/AsmPrinter.h>
|
#include <libyul/AsmPrinter.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
@ -33,42 +32,42 @@ using namespace solidity::yul;
|
|||||||
namespace solidity::frontend::experimental
|
namespace solidity::frontend::experimental
|
||||||
{
|
{
|
||||||
|
|
||||||
string IRNames::function(TypeEnvironment const& _env, FunctionDefinition const& _function, Type _type)
|
std::string IRNames::function(TypeEnvironment const& _env, FunctionDefinition const& _function, Type _type)
|
||||||
{
|
{
|
||||||
if (_function.isConstructor())
|
if (_function.isConstructor())
|
||||||
return constructor(*_function.annotation().contract);
|
return constructor(*_function.annotation().contract);
|
||||||
|
|
||||||
return "fun_" + _function.name() + "_" + to_string(_function.id()) + "$" + TypeEnvironmentHelpers{_env}.canonicalTypeName(_type) + "$";
|
return "fun_" + _function.name() + "_" + std::to_string(_function.id()) + "$" + TypeEnvironmentHelpers{_env}.canonicalTypeName(_type) + "$";
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRNames::function(VariableDeclaration const& _varDecl)
|
std::string IRNames::function(VariableDeclaration const& _varDecl)
|
||||||
{
|
{
|
||||||
return "getter_fun_" + _varDecl.name() + "_" + to_string(_varDecl.id());
|
return "getter_fun_" + _varDecl.name() + "_" + std::to_string(_varDecl.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRNames::creationObject(ContractDefinition const& _contract)
|
std::string IRNames::creationObject(ContractDefinition const& _contract)
|
||||||
{
|
{
|
||||||
return _contract.name() + "_" + toString(_contract.id());
|
return _contract.name() + "_" + toString(_contract.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRNames::deployedObject(ContractDefinition const& _contract)
|
std::string IRNames::deployedObject(ContractDefinition const& _contract)
|
||||||
{
|
{
|
||||||
return _contract.name() + "_" + toString(_contract.id()) + "_deployed";
|
return _contract.name() + "_" + toString(_contract.id()) + "_deployed";
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRNames::constructor(ContractDefinition const& _contract)
|
std::string IRNames::constructor(ContractDefinition const& _contract)
|
||||||
{
|
{
|
||||||
return "constructor_" + _contract.name() + "_" + to_string(_contract.id());
|
return "constructor_" + _contract.name() + "_" + std::to_string(_contract.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRNames::localVariable(VariableDeclaration const& _declaration)
|
std::string IRNames::localVariable(VariableDeclaration const& _declaration)
|
||||||
{
|
{
|
||||||
return "var_" + _declaration.name() + '_' + std::to_string(_declaration.id());
|
return "var_" + _declaration.name() + '_' + std::to_string(_declaration.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRNames::localVariable(Expression const& _expression)
|
std::string IRNames::localVariable(Expression const& _expression)
|
||||||
{
|
{
|
||||||
return "expr_" + to_string(_expression.id());
|
return "expr_" + std::to_string(_expression.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::frontend::experimental;
|
using namespace solidity::frontend::experimental;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
@ -64,10 +63,10 @@ m_context{_analysis, &m_env, {}, {}}
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerator::run(
|
std::string IRGenerator::run(
|
||||||
ContractDefinition const& _contract,
|
ContractDefinition const& _contract,
|
||||||
bytes const& /*_cborMetadata*/,
|
bytes const& /*_cborMetadata*/,
|
||||||
map<ContractDefinition const*, string_view const> const& /*_otherYulSources*/
|
std::map<ContractDefinition const*, std::string_view const> const& /*_otherYulSources*/
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ string IRGenerator::run(
|
|||||||
return t.render();
|
return t.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerator::generate(ContractDefinition const& _contract)
|
std::string IRGenerator::generate(ContractDefinition const& _contract)
|
||||||
{
|
{
|
||||||
std::stringstream code;
|
std::stringstream code;
|
||||||
code << "{\n";
|
code << "{\n";
|
||||||
@ -110,7 +109,7 @@ string IRGenerator::generate(ContractDefinition const& _contract)
|
|||||||
{
|
{
|
||||||
auto queueEntry = m_context.functionQueue.front();
|
auto queueEntry = m_context.functionQueue.front();
|
||||||
m_context.functionQueue.pop_front();
|
m_context.functionQueue.pop_front();
|
||||||
auto& generatedTypes = m_context.generatedFunctions.insert(std::make_pair(queueEntry.function, vector<Type>{})).first->second;
|
auto& generatedTypes = m_context.generatedFunctions.insert(std::make_pair(queueEntry.function, std::vector<Type>{})).first->second;
|
||||||
if (!util::contains_if(generatedTypes, [&](auto const& _generatedType) { return m_context.env->typeEquals(_generatedType, queueEntry.type); }))
|
if (!util::contains_if(generatedTypes, [&](auto const& _generatedType) { return m_context.env->typeEquals(_generatedType, queueEntry.type); }))
|
||||||
{
|
{
|
||||||
generatedTypes.emplace_back(queueEntry.type);
|
generatedTypes.emplace_back(queueEntry.type);
|
||||||
@ -121,7 +120,7 @@ string IRGenerator::generate(ContractDefinition const& _contract)
|
|||||||
return code.str();
|
return code.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerator::generate(FunctionDefinition const& _function, Type _type)
|
std::string IRGenerator::generate(FunctionDefinition const& _function, Type _type)
|
||||||
{
|
{
|
||||||
TypeEnvironment newEnv = m_context.env->clone();
|
TypeEnvironment newEnv = m_context.env->clone();
|
||||||
ScopedSaveAndRestore envRestore{m_context.env, &newEnv};
|
ScopedSaveAndRestore envRestore{m_context.env, &newEnv};
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
#include <range/v3/view/drop_last.hpp>
|
#include <range/v3/view/drop_last.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
@ -54,7 +53,7 @@ struct CopyTranslate: public yul::ASTCopier
|
|||||||
CopyTranslate(
|
CopyTranslate(
|
||||||
IRGenerationContext const& _context,
|
IRGenerationContext const& _context,
|
||||||
yul::Dialect const& _dialect,
|
yul::Dialect const& _dialect,
|
||||||
map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> _references
|
std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> _references
|
||||||
): m_context(_context), m_dialect(_dialect), m_references(std::move(_references)) {}
|
): m_context(_context), m_dialect(_dialect), m_references(std::move(_references)) {}
|
||||||
|
|
||||||
using ASTCopier::operator();
|
using ASTCopier::operator();
|
||||||
@ -83,8 +82,8 @@ struct CopyTranslate: public yul::ASTCopier
|
|||||||
return ASTCopier::translate(_identifier);
|
return ASTCopier::translate(_identifier);
|
||||||
|
|
||||||
yul::Expression translated = translateReference(_identifier);
|
yul::Expression translated = translateReference(_identifier);
|
||||||
solAssert(holds_alternative<yul::Identifier>(translated));
|
solAssert(std::holds_alternative<yul::Identifier>(translated));
|
||||||
return get<yul::Identifier>(std::move(translated));
|
return std::get<yul::Identifier>(std::move(translated));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -100,20 +99,20 @@ private:
|
|||||||
auto type = m_context.analysis.annotation<TypeInference>(*varDecl).type;
|
auto type = m_context.analysis.annotation<TypeInference>(*varDecl).type;
|
||||||
solAssert(type);
|
solAssert(type);
|
||||||
solAssert(m_context.env->typeEquals(*type, m_context.analysis.typeSystem().type(PrimitiveType::Word, {})));
|
solAssert(m_context.env->typeEquals(*type, m_context.analysis.typeSystem().type(PrimitiveType::Word, {})));
|
||||||
string value = IRNames::localVariable(*varDecl);
|
std::string value = IRNames::localVariable(*varDecl);
|
||||||
return yul::Identifier{_identifier.debugData, yul::YulString{value}};
|
return yul::Identifier{_identifier.debugData, yul::YulString{value}};
|
||||||
}
|
}
|
||||||
|
|
||||||
IRGenerationContext const& m_context;
|
IRGenerationContext const& m_context;
|
||||||
yul::Dialect const& m_dialect;
|
yul::Dialect const& m_dialect;
|
||||||
map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> m_references;
|
std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> m_references;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRGeneratorForStatements::visit(TupleExpression const& _tupleExpression)
|
bool IRGeneratorForStatements::visit(TupleExpression const& _tupleExpression)
|
||||||
{
|
{
|
||||||
std::vector<string> components;
|
std::vector<std::string> components;
|
||||||
for (auto const& component: _tupleExpression.components())
|
for (auto const& component: _tupleExpression.components())
|
||||||
{
|
{
|
||||||
solUnimplementedAssert(component);
|
solUnimplementedAssert(component);
|
||||||
@ -130,7 +129,7 @@ bool IRGeneratorForStatements::visit(InlineAssembly const& _assembly)
|
|||||||
{
|
{
|
||||||
CopyTranslate bodyCopier{m_context, _assembly.dialect(), _assembly.annotation().externalReferences};
|
CopyTranslate bodyCopier{m_context, _assembly.dialect(), _assembly.annotation().externalReferences};
|
||||||
yul::Statement modified = bodyCopier(_assembly.operations());
|
yul::Statement modified = bodyCopier(_assembly.operations());
|
||||||
solAssert(holds_alternative<yul::Block>(modified));
|
solAssert(std::holds_alternative<yul::Block>(modified));
|
||||||
m_code << yul::AsmPrinter()(std::get<yul::Block>(modified)) << "\n";
|
m_code << yul::AsmPrinter()(std::get<yul::Block>(modified)) << "\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -223,7 +222,7 @@ TypeRegistration::TypeClassInstantiations const& typeClassInstantiations(IRGener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDefinition const& IRGeneratorForStatements::resolveTypeClassFunction(TypeClass _class, string _name, Type _type)
|
FunctionDefinition const& IRGeneratorForStatements::resolveTypeClassFunction(TypeClass _class, std::string _name, Type _type)
|
||||||
{
|
{
|
||||||
TypeSystemHelpers helper{m_context.analysis.typeSystem()};
|
TypeSystemHelpers helper{m_context.analysis.typeSystem()};
|
||||||
|
|
||||||
@ -232,7 +231,7 @@ FunctionDefinition const& IRGeneratorForStatements::resolveTypeClassFunction(Typ
|
|||||||
auto typeVars = TypeEnvironmentHelpers{env}.typeVars(genericFunctionType);
|
auto typeVars = TypeEnvironmentHelpers{env}.typeVars(genericFunctionType);
|
||||||
solAssert(typeVars.size() == 1);
|
solAssert(typeVars.size() == 1);
|
||||||
solAssert(env.unify(genericFunctionType, _type).empty());
|
solAssert(env.unify(genericFunctionType, _type).empty());
|
||||||
auto typeClassInstantiation = get<0>(helper.destTypeConstant(env.resolve(typeVars.front())));
|
auto typeClassInstantiation = std::get<0>(helper.destTypeConstant(env.resolve(typeVars.front())));
|
||||||
|
|
||||||
auto const& instantiations = typeClassInstantiations(m_context, _class);
|
auto const& instantiations = typeClassInstantiations(m_context, _class);
|
||||||
TypeClassInstantiation const* instantiation = instantiations.at(typeClassInstantiation);
|
TypeClassInstantiation const* instantiation = instantiations.at(typeClassInstantiation);
|
||||||
@ -271,7 +270,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
|||||||
solAssert(declaration);
|
solAssert(declaration);
|
||||||
if (auto const* typeClassDefinition = dynamic_cast<TypeClassDefinition const*>(declaration))
|
if (auto const* typeClassDefinition = dynamic_cast<TypeClassDefinition const*>(declaration))
|
||||||
{
|
{
|
||||||
optional<TypeClass> typeClass = m_context.analysis.annotation<TypeInference>(*typeClassDefinition).typeClass;
|
std::optional<TypeClass> typeClass = m_context.analysis.annotation<TypeInference>(*typeClassDefinition).typeClass;
|
||||||
solAssert(typeClass);
|
solAssert(typeClass);
|
||||||
solAssert(m_expressionDeclaration.emplace(
|
solAssert(m_expressionDeclaration.emplace(
|
||||||
&_memberAccess,
|
&_memberAccess,
|
||||||
@ -299,7 +298,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
|||||||
{
|
{
|
||||||
Type functionType = type(_functionCall.expression());
|
Type functionType = type(_functionCall.expression());
|
||||||
auto declaration = m_expressionDeclaration.at(&_functionCall.expression());
|
auto declaration = m_expressionDeclaration.at(&_functionCall.expression());
|
||||||
if (auto builtin = get_if<Builtins>(&declaration))
|
if (auto builtin = std::get_if<Builtins>(&declaration))
|
||||||
{
|
{
|
||||||
switch(*builtin)
|
switch(*builtin)
|
||||||
{
|
{
|
||||||
@ -315,7 +314,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
|||||||
}
|
}
|
||||||
solAssert(false);
|
solAssert(false);
|
||||||
}
|
}
|
||||||
FunctionDefinition const* functionDefinition = dynamic_cast<FunctionDefinition const*>(get<Declaration const*>(declaration));
|
FunctionDefinition const* functionDefinition = dynamic_cast<FunctionDefinition const*>(std::get<Declaration const*>(declaration));
|
||||||
solAssert(functionDefinition);
|
solAssert(functionDefinition);
|
||||||
// TODO: get around resolveRecursive by passing the environment further down?
|
// TODO: get around resolveRecursive by passing the environment further down?
|
||||||
functionType = m_context.env->resolveRecursive(functionType);
|
functionType = m_context.env->resolveRecursive(functionType);
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include <libsolidity/ast/AST.h>
|
#include <libsolidity/ast/AST.h>
|
||||||
#include <libsolutil/StringUtils.h>
|
#include <libsolutil/StringUtils.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::frontend::experimental;
|
using namespace solidity::frontend::experimental;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
|
@ -29,6 +29,7 @@ NAMESPACE_STD_FREE_FILES=(
|
|||||||
libsolidity/ast/*
|
libsolidity/ast/*
|
||||||
libsolidity/codegen/ir/*
|
libsolidity/codegen/ir/*
|
||||||
libsolidity/codegen/*
|
libsolidity/codegen/*
|
||||||
|
libsolidity/experimental/*
|
||||||
libsolidity/formal/*
|
libsolidity/formal/*
|
||||||
libsolidity/interface/*
|
libsolidity/interface/*
|
||||||
libsolidity/lsp/*
|
libsolidity/lsp/*
|
||||||
|
Loading…
Reference in New Issue
Block a user