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

Function usingForDirectivesForType

libsolidity/ast/Types.cpp:345–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343{
344
345std::vector<UsingForDirective const*> usingForDirectivesForType(Type const& _type, ASTNode const& _scope)
346{
347 std::vector<UsingForDirective const*> usingForDirectives;
348 SourceUnit const* sourceUnit = dynamic_cast<SourceUnit const*>(&_scope);
349 if (auto const* contract = dynamic_cast<ContractDefinition const*>(&_scope))
350 {
351 sourceUnit = &contract->sourceUnit();
352 usingForDirectives += contract->usingForDirectives();
353 }
354 else
355 solAssert(sourceUnit, "");
356 usingForDirectives += ASTNode::filteredNodes<UsingForDirective>(sourceUnit->nodes());
357
358 if (Declaration const* typeDefinition = _type.typeDefinition())
359 if (auto const* sourceUnit = dynamic_cast<SourceUnit const*>(typeDefinition->scope()))
360 for (auto usingFor: ASTNode::filteredNodes<UsingForDirective>(sourceUnit->nodes()))
361 // We do not yet compare the type name because of normalization.
362 if (usingFor->global() && usingFor->typeName())
363 usingForDirectives.emplace_back(usingFor);
364
365 // Normalise data location of type.
366 DataLocation typeLocation = DataLocation::Storage;
367 if (auto refType = dynamic_cast<ReferenceType const*>(&_type))
368 typeLocation = refType->location();
369
370 return usingForDirectives | ranges::views::filter([&](UsingForDirective const* _directive) -> bool {
371 // Convert both types to pointers for comparison to see if the `using for` directive applies.
372 // Note that at this point we don't yet know if the functions are actually usable with the type.
373 // `_type` may not be convertible to the function parameter type.
374 return
375 !_directive->typeName() ||
376 *TypeProvider::withLocationIfReference(typeLocation, &_type, true) ==
377 *TypeProvider::withLocationIfReference(
378 typeLocation,
379 _directive->typeName()->annotation().type,
380 true
381 );
382 }) | ranges::to<std::vector<UsingForDirective const*>>;
383}
384
385}
386

Callers 2

operatorDefinitionsMethod · 0.85
attachedFunctionsMethod · 0.85

Calls 8

filterFunction · 0.85
usingForDirectivesMethod · 0.80
nodesMethod · 0.80
scopeMethod · 0.80
globalMethod · 0.80
typeDefinitionMethod · 0.45
typeNameMethod · 0.45
locationMethod · 0.45

Tested by

no test coverage detected