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

Method parse

libsolidity/interface/CompilerStack.cpp:364–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364bool CompilerStack::parse()
365{
366 solAssert(m_stackState == SourcesSet, "Must call parse only after the SourcesSet state.");
367 m_errorReporter.clear();
368
369 if (SemVerVersion{std::string(VersionString)}.isPrerelease())
370 m_errorReporter.warning(3805_error, "This is a pre-release compiler version, please do not use it in production.");
371
372 try
373 {
374 Parser parser{m_errorReporter, m_evmVersion, m_eofVersion};
375
376 std::vector<std::string> sourcesToParse;
377 for (auto const& s: m_sources)
378 sourcesToParse.push_back(s.first);
379
380 for (size_t i = 0; i < sourcesToParse.size(); ++i)
381 {
382 std::string const path = sourcesToParse[i];
383 Source& source = m_sources[path];
384 source.ast = parser.parse(*source.charStream);
385 if (!source.ast)
386 solAssert(Error::containsErrors(m_errorReporter.errors()), "Parser returned null but did not report error.");
387 else
388 {
389 source.ast->annotation().path = path;
390
391 for (auto const& import: ASTNode::filteredNodes<ImportDirective>(source.ast->nodes()))
392 {
393 solAssert(!import->path().empty(), "Import path cannot be empty.");
394 // Check whether the import directive is for the standard library,
395 // and if yes, add specified file to source units to be parsed.
396 auto it = stdlib::sources.find(import->path());
397 if (it != stdlib::sources.end())
398 {
399 auto [name, content] = *it;
400 m_sources[name].charStream = std::make_unique<CharStream>(content, name);
401 sourcesToParse.push_back(name);
402 }
403
404 // The current value of `path` is the absolute path as seen from this source file.
405 // We first have to apply remappings before we can store the actual absolute path
406 // as seen globally.
407 import->annotation().absolutePath = applyRemapping(util::absolutePath(
408 import->path(),
409 path
410 ), path);
411 }
412
413 if (m_stopAfter >= ParsedAndImported)
414 for (auto const& newSource: loadMissingSources(*source.ast))
415 {
416 std::string const& newPath = newSource.first;
417 std::string const& newContents = newSource.second;
418 m_sources[newPath].charStream = std::make_shared<CharStream>(newContents, newPath);
419 sourcesToParse.push_back(newPath);
420 }
421 }

Callers 1

generatedSourcesMethod · 0.45

Calls 10

isPrereleaseMethod · 0.80
nodesMethod · 0.80
pathMethod · 0.80
clearMethod · 0.45
warningMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45
maxIDMethod · 0.45

Tested by

no test coverage detected