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

Method resolveImports

libsolidity/interface/CompilerStack.cpp:1389–1442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1387}
1388
1389bool CompilerStack::resolveImports()
1390{
1391 solAssert(m_stackState == ParsedAndImported, "");
1392
1393 // topological sorting (depth first search) of the import graph, cutting potential cycles
1394 std::vector<Source const*> sourceOrder;
1395 std::set<Source const*> sourcesSeen;
1396
1397 std::function<void(Source const*)> toposort = [&](Source const* _source)
1398 {
1399 if (sourcesSeen.count(_source))
1400 return;
1401 sourcesSeen.insert(_source);
1402 solAssert(_source->ast);
1403 for (ASTPointer<ASTNode> const& node: _source->ast->nodes())
1404 if (ImportDirective const* import = dynamic_cast<ImportDirective*>(node.get()))
1405 {
1406 std::string const& path = *import->annotation().absolutePath;
1407 solAssert(m_sources.count(path), "");
1408 import->annotation().sourceUnit = m_sources[path].ast.get();
1409 toposort(&m_sources[path]);
1410 }
1411 sourceOrder.push_back(_source);
1412 };
1413
1414 std::vector<PragmaDirective const*> experimentalPragmaDirectives;
1415 for (auto const& sourcePair: m_sources)
1416 {
1417 if (isRequestedSource(sourcePair.first))
1418 toposort(&sourcePair.second);
1419 if (sourcePair.second.ast && sourcePair.second.ast->experimentalSolidity())
1420 for (ASTPointer<ASTNode> const& node: sourcePair.second.ast->nodes())
1421 if (PragmaDirective const* pragma = dynamic_cast<PragmaDirective*>(node.get()))
1422 if (pragma->literals().size() >=2 && pragma->literals()[0] == "experimental" && pragma->literals()[1] == "solidity")
1423 {
1424 experimentalPragmaDirectives.push_back(pragma);
1425 break;
1426 }
1427 }
1428
1429 if (!experimentalPragmaDirectives.empty() && experimentalPragmaDirectives.size() != m_sources.size())
1430 {
1431 for (auto &&pragma: experimentalPragmaDirectives)
1432 m_errorReporter.parserError(
1433 2141_error,
1434 pragma->location(),
1435 "File declares \"pragma experimental solidity\". If you want to enable the experimental mode, all source units must include the pragma."
1436 );
1437 return false;
1438 }
1439
1440 swap(m_sourceOrder, sourceOrder);
1441 return true;
1442}
1443
1444void CompilerStack::storeContractDefinitions()
1445{

Callers

nothing calls this directly

Calls 9

insertMethod · 0.80
nodesMethod · 0.80
countMethod · 0.45
getMethod · 0.45
experimentalSolidityMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
parserErrorMethod · 0.45
locationMethod · 0.45

Tested by

no test coverage detected