X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftoolchain.cpp;h=c5b8caa9ffb6dbe2b9e13b79eb9dd6e43083318e;hb=15cf75a5ac62454d90b8b2987b1940710056f4d0;hp=6c7dae1e5c43dd4c5391fd822ff1d4aa50572978;hpb=338eefb513953ae55e8e3614c009c242ba8ad74e;p=builder.git diff --git a/source/toolchain.cpp b/source/toolchain.cpp index 6c7dae1..c5b8caa 100644 --- a/source/toolchain.cpp +++ b/source/toolchain.cpp @@ -1,3 +1,4 @@ +#include #include #include "tool.h" #include "toolchain.h" @@ -7,8 +8,10 @@ using namespace Msp; Toolchain::~Toolchain() { - for(ToolMap::iterator i=tools.begin(); i!=tools.end(); ++i) - delete i->second; + for(const auto &kvp: tools) + delete kvp.second; + for(Toolchain *c: chains) + delete c; } void Toolchain::add_tool(Tool *tool) @@ -16,16 +19,40 @@ void Toolchain::add_tool(Tool *tool) insert_unique(tools, tool->get_tag(), tool); } -const Tool &Toolchain::get_tool(const string &tag) const +void Toolchain::add_toolchain(Toolchain *chain) { + auto i = upper_bound(chains, chain->get_priority(), [](int p, Toolchain *tc){ return p>tc->get_priority(); }); + chains.insert(i, chain); +} + +bool Toolchain::has_tool(const string &tag) const +{ + if(tools.count(tag)) + return true; + return any_of(chains.begin(), chains.end(), [&tag](Toolchain *tc){ return tc->has_tool(tag); }); +} + +Tool &Toolchain::get_tool(const string &tag) const +{ + if(!tools.count(tag)) + { + for(const Toolchain *c: chains) + if(c->has_tool(tag)) + return c->get_tool(tag); + } + return *get_item(tools, tag); } -const Tool *Toolchain::get_tool_for_suffix(const string &suffix) const +Tool *Toolchain::get_tool_for_suffix(const string &suffix, bool aux) const { - for(ToolMap::const_iterator i=tools.begin(); i!=tools.end(); ++i) - if(i->second->accepts_suffix(suffix)) - return i->second; + for(const auto &kvp: tools) + if(kvp.second->accepts_suffix(suffix, aux)) + return kvp.second; + + for(const Toolchain *c: chains) + if(Tool *tool = c->get_tool_for_suffix(suffix, aux)) + return tool; return 0; }