Skip to content

[libsolidity] Refactor Compiler Stack imported source type. #13578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void CompilerStack::importASTs(map<string, Json::Value> const& _sources)
m_sources[path] = std::move(source);
}
m_stackState = ParsedAndImported;
m_importedSources = true;
m_compilationSourceType = CompilationSourceType::SolidityAST;

storeContractDefinitions();
}
Expand Down Expand Up @@ -1482,7 +1482,17 @@ string CompilerStack::createMetadata(Contract const& _contract, bool _forIR) con
{
Json::Value meta{Json::objectValue};
meta["version"] = 1;
meta["language"] = m_importedSources ? "SolidityAST" : "Solidity";
string sourceType;
switch (m_compilationSourceType)
{
case CompilationSourceType::Solidity:
sourceType = "Solidity";
break;
case CompilationSourceType::SolidityAST:
sourceType = "SolidityAST";
break;
}
meta["language"] = sourceType;
meta["compiler"]["version"] = VersionStringStrict;

/// All the source files (including self), which should be included in the metadata.
Expand Down
9 changes: 8 additions & 1 deletion libsolidity/interface/CompilerStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ class CompilerStack: public langutil::CharStreamProvider
None
};

enum class CompilationSourceType {
/// Regular compilation from Solidity source files.
Solidity,
/// Compilation from an imported Solidity AST.
SolidityAST
};

/// Creates a new compiler stack.
/// @param _readFile callback used to read files for import statements. Must return
/// and must not emit exceptions.
Expand Down Expand Up @@ -511,7 +518,7 @@ class CompilerStack: public langutil::CharStreamProvider
langutil::DebugInfoSelection m_debugInfoSelection = langutil::DebugInfoSelection::Default();
bool m_parserErrorRecovery = false;
State m_stackState = Empty;
bool m_importedSources = false;
CompilationSourceType m_compilationSourceType = CompilationSourceType::Solidity;
/// Whether or not there has been an error during processing.
/// If this is true, the stack will refuse to generate code.
bool m_hasError = false;
Expand Down