Rename target selection to use the word artifact

This commit is contained in:
Alex Beregszaszi 2017-11-22 12:55:44 +00:00
parent 59bed63dbc
commit b2023196a2

View File

@ -131,43 +131,43 @@ StringMap createSourceList(Json::Value const& _input)
return sources; return sources;
} }
bool isTargetRequired(Json::Value const& _targets, string const& _target) bool isArtifactRequested(Json::Value const& _outputSelection, string const& _artifact)
{ {
for (auto const& target: _targets) for (auto const& artifact: _outputSelection)
/// @TODO support sub-matching, e.g "evm" matches "evm.assembly" /// @TODO support sub-matching, e.g "evm" matches "evm.assembly"
if (target == "*" || target == _target) if (artifact == "*" || artifact == _artifact)
return true; return true;
return false; return false;
} }
/// ///
/// @a _targets is a JSON object containining a two-level hashmap, where the first level is the filename, /// @a _outputSelection is a JSON object containining a two-level hashmap, where the first level is the filename,
/// the second level is the contract name and the value is an array of target names to be requested for that contract. /// the second level is the contract name and the value is an array of artifact names to be requested for that contract.
/// @a _file is the current file /// @a _file is the current file
/// @a _contract is the current contract /// @a _contract is the current contract
/// @a _target is the current target name /// @a _artifact is the current artifact name
/// ///
/// @returns true if the @a _targets has a match for the requested target in the specific file / contract. /// @returns true if the @a _outputSelection has a match for the requested target in the specific file / contract.
/// ///
/// In @a _targets the use of '*' as a wildcard is permitted. /// In @a _outputSelection the use of '*' as a wildcard is permitted.
/// ///
/// @TODO optimise this. Perhaps flatten the structure upfront. /// @TODO optimise this. Perhaps flatten the structure upfront.
/// ///
bool isTargetRequired(Json::Value const& _targets, string const& _file, string const& _contract, string const& _target) bool isArtifactRequested(Json::Value const& _outputSelection, string const& _file, string const& _contract, string const& _artifact)
{ {
if (!_targets.isObject()) if (!_outputSelection.isObject())
return false; return false;
for (auto const& file: { _file, string("*") }) for (auto const& file: { _file, string("*") })
if (_targets.isMember(file) && _targets[file].isObject()) if (_outputSelection.isMember(file) && _outputSelection[file].isObject())
{ {
if (_contract.empty()) if (_contract.empty())
{ {
/// Special case for SourceUnit-level targets (such as AST) /// Special case for SourceUnit-level targets (such as AST)
if ( if (
_targets[file].isMember("") && _outputSelection[file].isMember("") &&
_targets[file][""].isArray() && _outputSelection[file][""].isArray() &&
isTargetRequired(_targets[file][""], _target) isArtifactRequested(_outputSelection[file][""], _artifact)
) )
return true; return true;
} }
@ -176,9 +176,9 @@ bool isTargetRequired(Json::Value const& _targets, string const& _file, string c
/// Regular case for Contract-level targets /// Regular case for Contract-level targets
for (auto const& contract: { _contract, string("*") }) for (auto const& contract: { _contract, string("*") })
if ( if (
_targets[file].isMember(contract) && _outputSelection[file].isMember(contract) &&
_targets[file][contract].isArray() && _outputSelection[file][contract].isArray() &&
isTargetRequired(_targets[file][contract], _target) isArtifactRequested(_outputSelection[file][contract], _artifact)
) )
return true; return true;
} }
@ -187,10 +187,10 @@ bool isTargetRequired(Json::Value const& _targets, string const& _file, string c
return false; return false;
} }
bool isTargetRequired(Json::Value const& _targets, string const& _file, string const& _contract, vector<string> const& _requested) bool isArtifactRequested(Json::Value const& _outputSelection, string const& _file, string const& _contract, vector<string> const& _artifacts)
{ {
for (auto const& requested: _requested) for (auto const& artifact: _artifacts)
if (isTargetRequired(_targets, _file, _contract, requested)) if (isArtifactRequested(_outputSelection, _file, _contract, artifact))
return true; return true;
return false; return false;
} }
@ -460,9 +460,9 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
{ {
Json::Value sourceResult = Json::objectValue; Json::Value sourceResult = Json::objectValue;
sourceResult["id"] = sourceIndex++; sourceResult["id"] = sourceIndex++;
if (isTargetRequired(outputSelection, sourceName, "", "ast")) if (isArtifactRequested(outputSelection, sourceName, "", "ast"))
sourceResult["ast"] = ASTJsonConverter(false, m_compilerStack.sourceIndices()).toJson(m_compilerStack.ast(sourceName)); sourceResult["ast"] = ASTJsonConverter(false, m_compilerStack.sourceIndices()).toJson(m_compilerStack.ast(sourceName));
if (isTargetRequired(outputSelection, sourceName, "", "legacyAST")) if (isArtifactRequested(outputSelection, sourceName, "", "legacyAST"))
sourceResult["legacyAST"] = ASTJsonConverter(true, m_compilerStack.sourceIndices()).toJson(m_compilerStack.ast(sourceName)); sourceResult["legacyAST"] = ASTJsonConverter(true, m_compilerStack.sourceIndices()).toJson(m_compilerStack.ast(sourceName));
output["sources"][sourceName] = sourceResult; output["sources"][sourceName] = sourceResult;
} }
@ -477,28 +477,28 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
// ABI, documentation and metadata // ABI, documentation and metadata
Json::Value contractData(Json::objectValue); Json::Value contractData(Json::objectValue);
if (isTargetRequired(outputSelection, file, name, "abi")) if (isArtifactRequested(outputSelection, file, name, "abi"))
contractData["abi"] = m_compilerStack.contractABI(contractName); contractData["abi"] = m_compilerStack.contractABI(contractName);
if (isTargetRequired(outputSelection, file, name, "metadata")) if (isArtifactRequested(outputSelection, file, name, "metadata"))
contractData["metadata"] = m_compilerStack.metadata(contractName); contractData["metadata"] = m_compilerStack.metadata(contractName);
if (isTargetRequired(outputSelection, file, name, "userdoc")) if (isArtifactRequested(outputSelection, file, name, "userdoc"))
contractData["userdoc"] = m_compilerStack.natspecUser(contractName); contractData["userdoc"] = m_compilerStack.natspecUser(contractName);
if (isTargetRequired(outputSelection, file, name, "devdoc")) if (isArtifactRequested(outputSelection, file, name, "devdoc"))
contractData["devdoc"] = m_compilerStack.natspecDev(contractName); contractData["devdoc"] = m_compilerStack.natspecDev(contractName);
// EVM // EVM
Json::Value evmData(Json::objectValue); Json::Value evmData(Json::objectValue);
// @TODO: add ir // @TODO: add ir
if (isTargetRequired(outputSelection, file, name, "evm.assembly")) if (isArtifactRequested(outputSelection, file, name, "evm.assembly"))
evmData["assembly"] = m_compilerStack.assemblyString(contractName, createSourceList(_input)); evmData["assembly"] = m_compilerStack.assemblyString(contractName, createSourceList(_input));
if (isTargetRequired(outputSelection, file, name, "evm.legacyAssembly")) if (isArtifactRequested(outputSelection, file, name, "evm.legacyAssembly"))
evmData["legacyAssembly"] = m_compilerStack.assemblyJSON(contractName, createSourceList(_input)); evmData["legacyAssembly"] = m_compilerStack.assemblyJSON(contractName, createSourceList(_input));
if (isTargetRequired(outputSelection, file, name, "evm.methodIdentifiers")) if (isArtifactRequested(outputSelection, file, name, "evm.methodIdentifiers"))
evmData["methodIdentifiers"] = m_compilerStack.methodIdentifiers(contractName); evmData["methodIdentifiers"] = m_compilerStack.methodIdentifiers(contractName);
if (isTargetRequired(outputSelection, file, name, "evm.gasEstimates")) if (isArtifactRequested(outputSelection, file, name, "evm.gasEstimates"))
evmData["gasEstimates"] = m_compilerStack.gasEstimates(contractName); evmData["gasEstimates"] = m_compilerStack.gasEstimates(contractName);
if (isTargetRequired( if (isArtifactRequested(
outputSelection, outputSelection,
file, file,
name, name,
@ -509,7 +509,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
m_compilerStack.sourceMapping(contractName) m_compilerStack.sourceMapping(contractName)
); );
if (isTargetRequired( if (isArtifactRequested(
outputSelection, outputSelection,
file, file,
name, name,