MCPcopy Create free account
hub / github.com/argotorg/solidity / fresh

Method fresh

libsolidity/experimental/ast/TypeSystem.cpp:327–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327experimental::Type TypeEnvironment::fresh(Type _type)
328{
329 std::unordered_map<size_t, Type> mapping;
330 auto freshImpl = [&](Type _type, auto _recurse) -> Type {
331 return std::visit(util::GenericVisitor{
332 [&](TypeConstant const& _type) -> Type {
333 return TypeConstant{
334 _type.constructor,
335 _type.arguments | ranges::views::transform([&](Type _argType) {
336 return _recurse(_argType, _recurse);
337 }) | ranges::to<std::vector<Type>>
338 };
339 },
340 [&](TypeVariable const& _var) -> Type {
341 if (auto* mapped = util::valueOrNullptr(mapping, _var.index()))
342 {
343 auto* typeVariable = std::get_if<TypeVariable>(mapped);
344 solAssert(typeVariable);
345 // TODO: can there be a mismatch?
346 solAssert(typeVariable->sort() == _var.sort());
347 return *mapped;
348 }
349 return mapping[_var.index()] = m_typeSystem.freshTypeVariable(_var.sort());
350 },
351 [](std::monostate) -> Type { solAssert(false); }
352 }, resolve(_type));
353 };
354 return freshImpl(_type, freshImpl);
355}
356
357std::optional<std::string> TypeSystem::instantiateClass(Type _instanceVariable, Arity _arity)
358{

Callers 3

visitMethod · 0.80
polymorphicInstanceMethod · 0.80

Calls 4

valueOrNullptrFunction · 0.85
freshTypeVariableMethod · 0.80
indexMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected