diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-09-09 10:34:32 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-09-09 10:34:32 +0800 |
commit | 0442690894f918c9d6caf5f4fc9397888b98dcd7 (patch) | |
tree | b01f9fa0cd884434fa90fb9369b71c6f167f123d | |
parent | 52740ee4a6a5213b9f791fc55d5d69a42b377247 (diff) | |
download | mrust-0442690894f918c9d6caf5f4fc9397888b98dcd7.tar.gz |
cfg - Fix handling of `--cfg foo="bar"`
-rw-r--r-- | src/expand/cfg.cpp | 11 | ||||
-rw-r--r-- | src/main.cpp | 13 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/expand/cfg.cpp b/src/expand/cfg.cpp index 64e8a58e..8572b2e5 100644 --- a/src/expand/cfg.cpp +++ b/src/expand/cfg.cpp @@ -16,7 +16,7 @@ #include <map> #include <set> -::std::map< ::std::string, ::std::string> g_cfg_values; +::std::multimap< ::std::string, ::std::string> g_cfg_values; ::std::map< ::std::string, ::std::function<bool(const ::std::string&)> > g_cfg_value_fcns; ::std::set< ::std::string > g_cfg_flags; @@ -60,12 +60,15 @@ bool check_cfg(Span sp, const ::AST::MetaItem& mi) { } else if( mi.has_string() ) { // Equaliy - auto it = g_cfg_values.find(mi.name()); - if( it != g_cfg_values.end() ) + auto its = g_cfg_values.equal_range(mi.name()); + for(auto it = its.first; it != its.second; ++it) { DEBUG(""<<mi.name()<<": '"<<it->second<<"' == '"<<mi.string()<<"'"); - return it->second == mi.string(); + if( it->second == mi.string() ) + return true; } + if( its.first != its.second ) + return false; auto it2 = g_cfg_value_fcns.find(mi.name()); if(it2 != g_cfg_value_fcns.end() ) diff --git a/src/main.cpp b/src/main.cpp index f5412228..21e06b0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -744,11 +744,22 @@ ProgramParams::ProgramParams(int argc, char *argv[]) *p = '\0'; const char* opt = opt_and_val; const char* val = p + 1; + // TODO: Correctly parse the values. + // - Value should be a double-quoted string. if( ::std::strcmp(opt, "feature") == 0 ) { this->features.insert( ::std::string(val) ); } else { - Cfg_SetValue(opt, val); + if( val[0] == '"' ) { + // TODO: Something cleaner than this. + ::std::string s = val+1; + assert(s.back() == '"'); + s.pop_back(); + Cfg_SetValue(opt, s); + } + else { + Cfg_SetValue(opt, val); + } } } else { |