aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-03-30 18:16:28 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-11-30 04:10:04 +0800
commitd37e6ba1c7ade678644b5669b120bd76b72f39ea (patch)
treeecfa663e7812c388dbf1a581e1395f5d3a194f82 /libsolidity
parent07591478dd78dee56c5b83a62a314e984c3a83a6 (diff)
downloaddexon-solidity-d37e6ba1c7ade678644b5669b120bd76b72f39ea.tar
dexon-solidity-d37e6ba1c7ade678644b5669b120bd76b72f39ea.tar.gz
dexon-solidity-d37e6ba1c7ade678644b5669b120bd76b72f39ea.tar.bz2
dexon-solidity-d37e6ba1c7ade678644b5669b120bd76b72f39ea.tar.lz
dexon-solidity-d37e6ba1c7ade678644b5669b120bd76b72f39ea.tar.xz
dexon-solidity-d37e6ba1c7ade678644b5669b120bd76b72f39ea.tar.zst
dexon-solidity-d37e6ba1c7ade678644b5669b120bd76b72f39ea.zip
Add target selection helpers to StandardCompiler
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/interface/StandardCompiler.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp
index 430739ac..9aec7abb 100644
--- a/libsolidity/interface/StandardCompiler.cpp
+++ b/libsolidity/interface/StandardCompiler.cpp
@@ -131,6 +131,62 @@ StringMap createSourceList(Json::Value const& _input)
return sources;
}
+bool isTargetRequired(Json::Value const& _targets, string const& _target)
+{
+ for (auto const& target: _targets)
+ /// @TODO support sub-matching, e.g "evm" matches "evm.assembly"
+ if (target == "*" || target == _target)
+ return true;
+ return false;
+}
+
+///
+/// @a _targets 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.
+/// @a _file is the current file
+/// @a _contract is the current contract
+/// @a _target is the current target name
+///
+/// @returns true if the @a _targets has a match for the requested target in the specific file / contract.
+///
+/// In @a _targets the use of '*' as a wildcard is permitted.
+///
+/// @TODO optimise this. Perhaps flatten the structure upfront.
+///
+bool isTargetRequired(Json::Value const& _targets, string const& _file, string const& _contract, string const& _target)
+{
+ if (!_targets.isObject())
+ return false;
+
+ for (auto const& file: { _file, string("*") })
+ if (_targets.isMember(file) && _targets[file].isObject())
+ {
+ if (_contract.empty())
+ {
+ /// Special case for SourceUnit-level targets (such as AST)
+ if (
+ _targets[file].isMember("") &&
+ _targets[file][""].isArray() &&
+ isTargetRequired(_targets[file][""], _target)
+ )
+ return true;
+ }
+ else
+ {
+ /// Regular case for Contract-level targets
+ for (auto const& contract: { _contract, string("*") })
+ if (
+ _targets[file].isMember(contract) &&
+ _targets[file][contract].isArray() &&
+ isTargetRequired(_targets[file][contract], _target)
+ )
+ return true;
+ }
+ }
+
+ return false;
+}
+
Json::Value formatLinkReferences(std::map<size_t, std::string> const& linkReferences)
{
Json::Value ret(Json::objectValue);